Commit 60afe2f2 by 정용석

.cpp 추가

parent bdc17b34
#include <stdio.h>
char S[] = "#include <stdio.h>%cchar S[] = %c%s%c;%cint main() { printf(S, 10, 34, S, 34, 10); return 0; }";
int main() { printf(S, 10, 34, S, 34, 10); return 0; }
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
unsigned int my_strlen(char *s){
unsigned int i = 0;
while(s[i] != '\0'){
i++;
}
return i;
}
void my_strcpy(char *s1, char *s2) {
char copyS2[my_strlen(s2) + 1];
int i = 0;
while(s2[i] != '\0'){
copyS2[i] = s2[i];
i++;
}
if(my_strlen(s1) <= my_strlen(s2)){
printf("Error : 첫 번째 인자의 배열의 크기가 두 번째 인자의 크기보다 작기 때문에 정상적인 복사가 되지않습니다.\n");
}else{
while(*s1++ = *s2++);
}
}
int main() {
char s1[] = "abcd";
char s2[] = "efghijk";
my_strcpy(s1, s2);
printf("%s\n%s\n", s1, s2);
char s3[] = "abcdefg";
char s4[] = "hijk";
my_strcpy(s3, s4);
printf("%s\n%s\n", s3, s4);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment