排序学生成绩 然后打印在文件里面 出现重复定义错误
#include<stdio.h>#include<stdlib.h>
#define N 20
void readFile(STUDENT stu[]);
void rankScore(STUDENT stu[], STUDENT temp);
void printToFile(STUDENT stu[]);
typedef struct student
{
long ID;
char name[20];
int height;
int weight;
int score[4];
} STUDENT;
int main()
{
STUDENT stu[N], temp;
readFile(stu);
rankScore(stu,temp);
printToFile(stu);
return 0;
}
void readFile(STUDENT stu[])
{
int i, j;
FILE *fp;
fp = fopen("d:\\学生信息.txt","r");
if( fp==NULL )
{
printf("Failure to write to file!\n");
exit(0);
}
for( i=0; i<2; i++ )
{
fscanf(fp,"%10ld",&stu[i].ID);
fscanf(fp,"%8s",&stu[i].name);
fscanf(fp,"%5d",&stu[i].height);
fscanf(fp,"%5d",&stu[i].weight);
for( j=0; j<4; j++ )
{
fscanf(fp,"%4d",&stu[i].score[j]);
}
}
fclose(fp);
}
void rankScore(STUDENT stu[], STUDENT temp)
{
int sum[20] ={0};
int m, n ;
for( m=0; m<2; m++ )
{
sum[m] = 0;
for( n=0; n<4; n++ )
{
sum[m] = stu[m].score[n];
}
}
for( m=0; m<2; m++ )
{
for( n=m+1; n<2; n++ )
{
if( sum[m]>sum[n] )
{
temp = stu[m];
stu[n] = stu[m];
stu[m] = temp;
}
}
}
}
void printToFile(STUDENT stu[])
{
int i, j;
FILE *fp;
fp = fopen("d:\\学生成绩排序.txt","w");
if( fp==NULL )
{
printf("Failure to write to file!\n");
exit(0);
}
for( i=0; i<2; i++ )
{
fprintf(fp,"%10d%8s%5d%5d",stu[i].ID,stu[i].name,stu[i].height,stu[i].weight);
for(j=0; j<4; j++ )
{
fprintf(fp,"%4d",stu[i].score[j]);
}
fprintf(fp,"\n");
}
e:\vc6.0\wek14_3.c(4) : error C2146: syntax error : missing ')' before identifier 'stu'
e:\vc6.0\wek14_3.c(4) : error C2061: syntax error : identifier 'stu'
e:\vc6.0\wek14_3.c(4) : error C2059: syntax error : ';'
e:\vc6.0\wek14_3.c(4) : error C2059: syntax error : '['
e:\vc6.0\wek14_3.c(4) : error C2059: syntax error : ')'
e:\vc6.0\wek14_3.c(5) : error C2146: syntax error : missing ')' before identifier 'stu'
e:\vc6.0\wek14_3.c(5) : error C2061: syntax error : identifier 'stu'
e:\vc6.0\wek14_3.c(5) : error C2059: syntax error : ';'
e:\vc6.0\wek14_3.c(5) : error C2059: syntax error : '['
e:\vc6.0\wek14_3.c(5) : error C2059: syntax error : ')'
e:\vc6.0\wek14_3.c(6) : error C2146: syntax error : missing ')' before identifier 'stu'
e:\vc6.0\wek14_3.c(6) : error C2061: syntax error : identifier 'stu'
e:\vc6.0\wek14_3.c(6) : error C2059: syntax error : ';'
e:\vc6.0\wek14_3.c(6) : error C2059: syntax error : '['
e:\vc6.0\wek14_3.c(6) : error C2059: syntax error : ')'
e:\vc6.0\wek14_3.c(19) : warning C4013: 'reaFile' undefined; assuming extern returning int
e:\vc6.0\wek14_3.c(20) : warning C4013: 'rankScore' undefined; assuming extern returning int
e:\vc6.0\wek14_3.c(21) : warning C4013: 'printToFile' undefined; assuming extern returning int
e:\vc6.0\wek14_3.c(28) : error C2371: 'reaFile' : redefinition; different basic types
e:\vc6.0\wek14_3.c(56) : error C2371: 'rankScore' : redefinition; different basic types
e:\vc6.0\wek14_3.c(87) : error C2371: 'printToFile' : redefinition; different basic types
e:\vc6.0\wek14_3.c(111) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
是哪里出错了呢 检查一半天看不出来