新新新手求助 字符串与指针的问题
我想用指针实现将t中的字符复制到s的末尾,如下的代码输出的怎么还是原先s的值呢?
c 指针
#include <stdio.h>
void strcat(char *s,char *t)
{
while (*s++ != '\0')
;
while (*s++=*t++)
;
}
int main()
{
char s[20]="hello,"; char t[10]="world";
strcat(s,t);
printf("the new str is %s\n",s);
return 0;
}
[解决办法]
void strcat(char *s,char *t)
{
while (*++s != '\0')
;
while (*s++=*t++)
;