我正在写strcat函数
/*appends source string to destination string*/
#include <stdio.h>
int main()
{
char srcstr[100], deststr[100];
char *psrcstr, *pdeststr;
printf("\n Enter source string: ");
gets(srcstr);
printf("\n Enter destination string: ");
gets(deststr);
pdeststr = deststr;
psrcstr = srcstr;
while(*pdeststr++)
;
while(*pdeststr++ = *psrcstr++)
;
printf("%s", deststr);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
对于srcstr = " world"和deststr = "hello"我得到的hello,我希望看到hello world,这是我所看到的,如果我第一次改变while这样
while(*pdeststr);
pdeststr++;
Run Code Online (Sandbox Code Playgroud)
为什么我不能在第一行中写所有内容while,就像在第二行一样while?