i write this:
and the output is:Code:#include <stdio.h> #include <string.h> int main() { char s[15]; strcat(s,"abcde"); fputs(s,stdout); getch(); return 0; }
Image
Where did I go wrong?
i write this:
and the output is:Code:#include <stdio.h> #include <string.h> int main() { char s[15]; strcat(s,"abcde"); fputs(s,stdout); getch(); return 0; }
Image
Where did I go wrong?
s[15] is created on the program's stack (because it's inside a function)... thus it's content is not reset to nulls and when you do strcat you also get whatever junk is in the stack at the address of the array...
Try it like this:
In practical aps you have two choices... a) use strcpy() the first time then strcat() after or b) clear the memory to 0 as I showed you.Code:char s[15] = {0}; strcat(s,"abcde");
ok,tanks
I use point b)
L.E: in this exemple why the output is correct???
sorry,now I see
first is use strcpy()