amanayin said:
#include<stdio.h>
#include<string.h>
int main(void)
{
char a[3] = "ab";
char b[3] = "cd";
char c[5] = " ";
strcpy(c,a);
strcat(c,b);
printf("a is %s\n",a);
printf("b is %s\n",b);
printf("c is %s\n",c);
}
See your problem
Other than function main not returning an int, what is the problem?
The char array a[3] has been initialized and a points to a string "ab".
The char array b[3] has been initialized and b points to a string "cd".
The char array c[5] is different. There is enough space in
the array to store the five space characters, ' ', but
not for a terminating null character. So the null character
is not included and c is simply an array of five space
characters. It is not a string. But this is not a problem in this
code.
The function strcpy copies the string pointed to by a into the
char arrary pointed to by c. c is now a string "ab".
The function strcat appends the string pointed to by b onto the
string pointed to by c. c now points to the string "abcd".
Since there is enough storage for the operations and there is
no overlapping of objects, the code is ok.