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

读取文件 ,发现文件里的数据多了,该怎么解决

2012-06-04 
读取文件 ,发现文件里的数据多了C/C++ code文本文件:12347890668778读取后,把数据放到一个数组中int

读取文件 ,发现文件里的数据多了

C/C++ code
文本文件:1234;78;90;668;778;读取后,把数据放到一个数组中int main(){FILE* file;file=fopen("test.txt","r");if(!file){    cerr<<"error"<<endl;    return -1;}int arr[2000];int count=0;while(!feof(file) ){    char strOneLine[256];     fscanf(file, "%s",strOneLine); //读入之后    //分解到int arr中    char* p=strtok(strOneLine,";");    while(p)    {        arr[count++]=atoi(p);        cout<<p<<endl;        p=strtok(NULL,";");    }}    cout<<"有:"<<count<<"个元素"<<endl;fclose(file);return 0;}代码运行后,发现有6个元素,是怎么回事啊???不是5个,




[解决办法]
老问题,

while (fscanf() == 1)

热点排行