注册 登录
编程论坛 C++教室

请教个死循环问题~~~

tiw 发布于 2008-03-20 14:28, 1117 次点击
#include<stdio.h>
#include<string.h>
main()
{   char xx[]="1,2,3,4,5,0";
    strcat(xx,"6789");
    printf("%s\n",xx);

}

运行时出现死循环,持续输出1,2,3,4,5,06789
去掉0时可以正常运行,且出现abnormal program termination,其他就不行
10 回复
#2
sunkaidong2008-03-20 14:57
开辟大一点的数组空间
#3
tiw2008-03-20 21:05
恩是下标不够大~~~~
#4
醉生梦死2008-03-22 08:04
不懂~难道输出1,2,3,4,5,06789不对么?感觉就应该输出1,2,3,4,5,06789啊
#5
醉生梦死2008-03-22 08:05
不懂~难道输出1,2,3,4,5,06789不对么?感觉就应该输出1,2,3,4,5,06789啊
#6
xianshizhe1112008-03-22 13:28
abnormal program termination
程序异常终止.
#7
handongxue2008-03-25 23:49
的确是溢出错误
char xx[]="1,2,3,4,5,0";和char xx[12]="1,2,3,4,5,0";是等价的。
就像 int a[]={2,3,4,5};等价与int a[4]={2,3,4,5};
所以strcat(xx,"6789");执行后就会出现错误。由于长度不够。
#8
haxin2008-03-26 09:46
学习了
#9
bcxye2008-03-26 10:39
恩  挺好 学了
#10
sunhao68772008-03-26 14:37
.....看不懂  我还需要继续学习
#11
izwttc2008-03-26 14:41
努力中 努力中努力中努力中努力中努力中努力中努力中
1