文件怎么打不开呢?
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#include"dazuoye.h"
void readFile()
{
int n;
struct stuMessage *head ,*temp;
FILE *inFile;
inFile = fopen("stuImformation.txt","r");
if(inFile == NULL)
{
printf("文件打开失败,请检查文件是否存在");
exit(1);
}
else
{
while(fscanf(inFile,"%s %s %s\n",head->name,head->idnum,head->Clanum)!=EOF)
{
head->nextaddr = NULL;
if(firstaddr==NULL)
{
firstaddr=head;
temp=head;
}
else
{
temp->nextaddr=head;
temp=head;
}
head=(struct stuMessage *)malloc(sizeof(struct stuMessage *));
}
}
fclose(inFile);
}
void saveFile()
{
struct stuMessage *temp;
FILE *outFile;
int n;
outFile=fopen("stuImformation.txt","w");
if(outFile==NULL)
{
printf("文件打开失败!");
exit(1);
}
while(firstaddr!=NULL)
{
temp=firstaddr;
firstaddr=firstaddr->nextaddr;
fprintf(outFile,"%s %s %s",temp->name,temp->idnum,temp->Clanum);
for(n=0;n<10;n++)
{
fprintf(outFile,"%f",temp->grade[n]);
free(temp);
}
fprintf(outFile,"\n",0);
}
fclose(outFile);
}