怎样判断c语言文件存在但是否为空啊?急!!!
比如说:structstudent*pen(){FILE*fp;structstudent*p1,*head,*p2;p1=(structstudent*)malloc(...
比如说:
struct student * pen()
{
FILE *fp;
struct student *p1,*head,*p2;
p1=(struct student *)malloc(LEN);
if((fp=fopen("student.dat","rb"))==NULL)
head=NULL;
else
{
fread(p1,LEN,1,fp);
head=p1;
if(p1!=NULL)
while(p1->next!=NULL)
{
p2=(struct student *)malloc(LEN);
fread(p2,LEN,1,fp);
p1->next=p2;
p1=p2;
}
}
fclose(fp);
return(head);
}
就是说文件已经存在了,但里面是否有内容,怎样判断? 展开
struct student * pen()
{
FILE *fp;
struct student *p1,*head,*p2;
p1=(struct student *)malloc(LEN);
if((fp=fopen("student.dat","rb"))==NULL)
head=NULL;
else
{
fread(p1,LEN,1,fp);
head=p1;
if(p1!=NULL)
while(p1->next!=NULL)
{
p2=(struct student *)malloc(LEN);
fread(p2,LEN,1,fp);
p1->next=p2;
p1=p2;
}
}
fclose(fp);
return(head);
}
就是说文件已经存在了,但里面是否有内容,怎样判断? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询