| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1046 人关注过本帖
标题:排序学生成绩 然后打印在文件里面 出现重复定义错误
取消只看楼主 加入收藏
Poppy辉
Rank: 1
来 自:云南曲靖
等 级:新手上路
帖 子:33
专家分:4
注 册:2016-11-5
结帖率:66.67%
收藏
已结贴  问题点数:14 回复次数:1 
排序学生成绩 然后打印在文件里面 出现重复定义错误
#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 时出错.

是哪里出错了呢 检查一半天看不出来
搜索更多相关主题的帖子: include return 
2016-12-29 19:44
Poppy辉
Rank: 1
来 自:云南曲靖
等 级:新手上路
帖 子:33
专家分:4
注 册:2016-11-5
收藏
得分:0 
回复 4楼 九转星河
很感谢  就是这个问题 谢谢啦。
2016-12-29 20:38
快速回复:排序学生成绩 然后打印在文件里面 出现重复定义错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.053830 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved