二级C语言问题

来源:百度知道 编辑:UC知道 时间:2024/09/22 11:33:41
#include <stdio.h>
void fun(char *t,char *s)
{
while (*t !=0) t++;
while ((*t++ = *s++) 1= 0);
}
main ()
{
char ss[10]="acc",aa[10]="bbxxyy";
fun(ss,aa);printf(%s,%s\n,ss,aa);
}
这个程序会输出什么 大家帮忙看看!书上就是这么写得,我在VC上运行不出来,哪位大侠知道的话顺便给讲细点!

书上应该是这样写的吧
#include <stdio.h>
void fun(char *t,char *s)
{
while (*t !=0)
t++;
while ((*t++ = *s++) != 0);
}
main ()
{
char ss[10]="acc",aa[10]="bbxxyy";
fun(ss,aa);
printf("%s,%s\n",ss,aa);
}

结果是
accbbxxyy bbxxyy
有些地方你大错了
while ((*t++ = *s++) 1= 0);//!打成1
main函数中的printf()函数也楼了“”;
fun函数的作用是连接两个字符串
首先
while(*t!=0)t++;的作用是使用字符指针指向第一个字符串的最后一个字符的后面。
while ((*t++ = *s++) 1= 0);
这个的作用是将第二个字符串复制给第一个字符串的最后.