| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 711 人关注过本帖
标题:上机考试题,老做不对,望各位师傅指导!
取消只看楼主 加入收藏
rlqfj
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-3-30
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
上机考试题,老做不对,望各位师傅指导!
已存在二进制数据文件date1,其结构由姓名、学号、成绩(语文、数学、英语)组成。文件中存有(林、王、吴)三个学生的数据。请打印输出三位学生数学成绩最高的学生的姓和学号。
程序名为k26

#include<stdio.h>
#define N 3
struct student
{ char name[10];
  int num;
  int score[N];}
  stud[N];
main()
{




close(fp);
}
搜索更多相关主题的帖子: 指导 上机 考试 师傅 
2010-03-30 10:50
rlqfj
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-3-30
收藏
得分:0 
以下是引用ldg628在2010-3-30 11:03:15的发言:

main()
{
    FILE *fp;
    int i;
    struct student *stumax;
    fp = fopen("date1", "r");
    fread(stu, sizeof(struct student), N, fp);
    stumax = stu;
    for (i = 1; i < N; i ++)
    {
        if (stumax->score[1] < stu.score)
        {
            stumax = &stu;
        }
    }
    printf("math score: %d, name : %s, num : %d\n", stumax->score[1], stumax->name, stumax->num);
    close(fp);
}
不对啊。把STU改成STUD也不行。
说 if (stumax->score[1] < stu.score)非法的结构运算在main函数中
        
2010-03-30 11:30
rlqfj
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-3-30
收藏
得分:0 
#define N 3
#include <stdio.h>
struct student{ char name[10];
        int num;
        int  score[3];
             }stud[N];
main()
{ FILE *fp;

 int k,j;
 int  x,a[3];
 int max,max_x;
  max=0;
  max_x=0;
 if((fp=fopen("data1.dat","rb"))==NULL)
 { printf("file not open!\n"); exit(0); }
 for(k=0;k<3;k++)
 {fread(&stud,sizeof(struct student),3,fp);
 a[k]=stud[k].score[0]+stud[k].score[1]+stud[k].score[2];
 printf("%s,%d,%d,%d,%d,%d\n",stud[k].name,stud[k].num,stud[k].score[0],stud[k].score[1],stud[k].score[2],a[k]);
 }
if(a[0]>=a[1]&&a[0]>=a[2]) max_x=0;
if(a[1]>=a[2]&&a[1]>=a[0]) max_x=1;
if(a[2]>=a[1]&&a[2]>=a[0]) max_x=2;

printf("score-max:\n");
printf("name:%s,num:%d,score1:%d,score2:%d,score3:%d,\n",stud[max_x].name,stud[max_x].num,stud[max_x].score[0],stud[max_x].score[1],stud[max_x].score[2]);
 fclose(fp);
     getch();
}

谢谢小飞侠!

[ 本帖最后由 rlqfj 于 2010-3-30 14:31 编辑 ]
2010-03-30 14:29
快速回复:上机考试题,老做不对,望各位师傅指导!
数据加载中...
 
   



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

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