有趣的错误

来源:互联网 发布:淘宝代拍是怎么拍到的 编辑:程序博客网 时间:2024/05/16 23:50
 
这段程序
strPathName="C://MyCalendar//todolist.txt";
FILE *pFile=fopen(strPathName,"r");
int count=0;
fscanf(pFile,"%d",&count);
char* str;
CString tmp;
for (int i=0; i<count; i++)
{
            fscanf(pFile,"%s",&str);
}
这段程序在编译的时候没有任何错误
不过程序一运行就出现了 一件令人吃惊的事情
比如todolist.txt中有两行数据
1
Abcdefgh
那么count=1,str=Abcdefgh这是我所希望的
但是
在count取到1之后,进入了for循环,
str取到Abcdefgh,可是count的值也改变了
原创粉丝点击