为什么打 不开文件啊,我在D:盘建了文件了啊,怎么打不开啊,用记事本建的,哪位高人指点啊??????不胜感激啊!!!!!!
如何建立文件,用tc,指教!1
#include"stdio.h"
void OpenFile(void);
void PrnHeadings(void);
void ProcessLoop(void);
void ReadRecord(void);
float CalcTotal(void);
float CalcAvr(float);
void PrnDetail(float);
char PT1[]=" S I X-W E E K S G R A D E R E P O R T ";
char HL1[]="student text Score Average";
char HL2[]="-----------------------------------------------";
FILE *fpGrade;
char sStudent[16];
int iGrade1;
int iGrade2;
int iGrade3;
int iGrade4;
int iGrade5;
int iGrade6;
main()
{
OpenFile();
if(fpGrade!=0)
{
PrnHeadings();
ProcessLoop();
fclose(fpGrade);
}
return;
}
void OpenFile(void)
{
fpGrade=fopen("d:txGrades.txt","r");
if(fpGrade==0)
{
printf("\nCannot open grades file for input\n");
}
return;
}
void PrnHeadings(void)
{
printf(PT1);
printf("\n\n\n");
printf(HL1);
printf("\n");
printf(HL2);
printf("\n");
return;
}
void ProcessLoop(void)
{
float fGradeTot;
float fGradeAvr;
ReadRecord();
while(!feof(fpGrade))
{
fGradeTot=CalcTotal();
fGradeAvr=CalcAvr(fGradeTot);
PrnDetail(fGradeAvr);
ReadRecord();
}
return;
}
void ReadRecord(void)
{
fscanf(fpGrade,"%15[^\n] %d %d %d %d %d %d",sStudent,&iGrade1,&iGrade2,&iGrade3,&iGrade4,&iGrade5,&iGrade6);
return;
}
float CalcTotal(void)
{
float fGradeTot;
fGradeTot=iGrade1+iGrade2+iGrade3+iGrade4+iGrade5+iGrade6;
return fGradeTot;
}
float CalcAvr(float fGradeTot)
{
float fGradeAvr;
fGradeAvr=fGradeTot/6;
return fGradeAvr;
}
void PrnDetail(float fGradeAvr)
{
printf("\n %-15s %3d %3d %3d %3d %3d %3d %6.2f",sStudent,iGrade1,
iGrade2,iGrade3,iGrade4,iGrade5,iGrade6,fGradeAvr);
return;
}