最近在家又开始看一看C 结果发现文件这块不太熟练 用的时候发现使用文件读取txt里的内容时读不到第一行的内容 感到有些疑惑 我用的是devcpp 希望有老哥指点一二
#include<iostream>
#include<cstring>
using namespace std;
int block_num=0;
int page_num=0;
int river[20]={0};
void read_data()
{
FILE *fp;
fp=fopen("page.txt","rt");
if(fp==NULL)
{
printf("error!\n");
exit(0);
}
char buffer[100];
fgets(buffer,100,fp);
fscanf(fp,"%d%d",&block_num,&page_num);
/*do
{
fscanf(fp,"%d",&block_num);
fscanf(fp,"%d",&page_num);
for(int i = 0;i<page_num;i++)
{
fscanf(fp,"%d",&river[i]);
}
}while(!feof(fp));*/
cout<<"block_num is "<<block_num<<"page_num is "<<page_num<<endl;
/* for(int i=0;i<page_num;i++)
cout<<river[i]<<" "<<endl;*/
}
int main()
{
read_data();
}