首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

运行后中断,缓冲区,堆栈有关问题

2013-12-19 
运行后中断,缓冲区,堆栈问题中断原因Run-Time Check Failure #2 - Stack around the variable buff was

运行后中断,缓冲区,堆栈问题
中断原因
Run-Time Check Failure #2 - Stack around the variable 'buff' was corrupted.
应该是堆栈损坏了

代码如下:
struct num{
int row;
int studentnumber;
};
num buff[2];
memset(&buff,0,sizeof(buff)*2);

        printf("%d %d",buff[0].row ,buff[0].studentnumber );
printf("%d %d",buff[1].row ,buff[1].studentnumber );

 在输出的时候中断了,按照把“project->配置属性->c/c++->代码生成->基本运行时检查 设置为默认值,就没有这样的错误了。 更改后正常,我想知道这样写到底好不好,是不是自己那里写错了。
[解决办法]
memset(&buff,0,sizeof(buff)*2);改为
memset(buff,0,sizeof(struct num)*2);
[解决办法]
不要把
fopen("...","...");fscanf,fprintf,fclose //读时把\r\n替换成\n,写时把\n替换成\r\n;读到\x1a就设置EOF;读写的内容当字符看待

fopen("...","...b");fread,fwrite,fclose  //不作以上替换,遇到\x1a仍继续读;读写的内容当字节看待
弄混了

热点排行