以下是引用xsimon在2006-5-17 19:37:00的发言:
#include<stdio.h>
/* strcat: concatenate t to end of s; s must be big enough */
void strcat(char s[], char t[])
{
int i, j;
i = j = 0;
while (s[i++] != '\0'); /* find end of s */
while ((s[i++] = t[j++]) != '\0'); /* copy t */
}
int main (void)
{
char s[15]= "Boy And ", t[5] = "Girl"; /*如果把t[5]改为t[4],则得不到正确的值, 但"girl"的长度是为4呀. 难道要包括'\0'*/
strcat (s, t);
printf ("%s\n", s);
getch ();
return 0;
}
字符数组的长度和元素个数不一样的