65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void)
{
char ch[100];
FILE * p = fopen("d:\\data.txt","r");
if (p!=NULL)
{
for(int i = 0; i < 6; i++)
{
fscanf(p,"%s",ch);
if(i > 4)
cout <<ch <<endl;
}
}
else
{
cerr<<"open failed"<<endl;
exit(-1);
}
fclose(p);
return 0;
}
FILE * p = fopen("a.txt","r"); //程式找不到a.txt, 这时p = NULL;
fscanf(p,"%s",ch); //这里对p操作,但其为NULL,所以报错