strcat(s,t) copies the string t to the end of s,the following is initial code.
void strcat(char s[], char t[])
{
int i, j;
i = 0;
j = 0;
while (s[++i] != '\0');
while ((s[i++] = t[j++]) != '\0');
}
#define MaxSize 100
int main()
{
char str1[MaxSize] = { 'a','b','c','d' };
char str2[MaxSize] = { 's','s' };
strcat(str1, str2);
printf("%s", str1);
return 0;
}
“void (char *,char *)”
and“char *(char *,const char *)”
. this is the first why?void strcat(char s[], char t[])
to void* strcat(char s[], char t[])
there is no error. so it means i can only use pointer void*
to strcat(char s[], char t[])
to modify the content of str1. if what i think is right,that will be the second whythank you guys very much, i should change the function name. e.g. void strcat(char s[], char t[]) should be modified to void mystrcat(char s[], char t[]).
i want to use my own version of strcat but forgot it violated the C language specification. because i wrote code # include< string.h>.
after i realize this problem, void strcat(char s[], char t[]) and void strcat(char s[], char t[]) are both OK.