| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1163 人关注过本帖
标题:请大家看看我这个程序错在那里
只看楼主 加入收藏
海纳百川
Rank: 1
来 自:湖北荆州
等 级:新手上路
帖 子:186
专家分:5
注 册:2007-10-2
收藏
 问题点数:0 回复次数:10 
请大家看看我这个程序错在那里
#include "stdio.h"
#define SIZE 5
struct student
{char name[10];
 int num;
 int score[3];
 float ave;
} stu[SIZE];
void main()
{void save(void);
 int i;
 float sum[SIZE];
 FILE *fp1;
 for(i=0;i<SIZE;i++)
    {scanf("%s %d %d %d %d",stud[i].name,&stud[i].num,&stud[i].score[0],这行运行
老出错stud这个有错      &stud[i].score[1],&stud[i].score[2]);
      sum[i]=stud[i].score[0],+stud[i].score[1]+stud[i].score[2]+stud[2];
      stud[i].ave=sum[i]/3;
    }
    save();
 fp1=fopen("stu.dat","rb");
 printf("\n name    No   score1 score2 score3 ave\n");
 printf("----------------------------------------\n");
 for(i=0;i<SIZE;i++)
    {fread(&stud[i],sizeof(struct student),1,fp1);
     printf("%-10s %3d %7d %7d %7d %8.2f\n",stud[i].name,stud[i].name,
     stud[i].score[0],stud[i].score[1],stud[i].score[2],stud[i].ave);
    }
 fclose (fp1);
}
void save(void)
{FILE *fp;
 int i;
 if((fp=fopen("stu.dat","wb"))==NULL)
    {printf("The file can not open\n");
     return;
    }
 for(i=0;i<SIZE;i++)
    if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
      {printf("file write error\n");
       return;
      }
 fclose(fp);
}
请大家给我指出来
在这我谢谢大家了哦
搜索更多相关主题的帖子: void include 
2008-08-06 22:47
xlh5225
Rank: 2
等 级:论坛游民
威 望:2
帖 子:188
专家分:25
注 册:2007-8-14
收藏
得分:0 
天呢,你的程序太乱了
2008-08-06 22:55
缘为何物
Rank: 1
等 级:新手上路
帖 子:34
专家分:4
注 册:2008-8-6
收藏
得分:0 
貌似第一行就出错了,不是应该用那个号<>括起来的?我刚学一天,不知道对不对,请指教。
2008-08-06 23:40
blueboy82006
Rank: 5Rank: 5
来 自:幻想世界
等 级:贵宾
威 望:16
帖 子:1227
专家分:57
注 册:2007-7-23
收藏
得分:0 
scanf("%s %d %d %d %d",stud[i].name,&stud[i].num,&stud[i].score[0],&stud[i].score[1],&stud[i].score[2]);
上面可是stu
这行却写成stud了

2008-08-06 23:41
blueboy82006
Rank: 5Rank: 5
来 自:幻想世界
等 级:贵宾
威 望:16
帖 子:1227
专家分:57
注 册:2007-7-23
收藏
得分:0 
回复 3# 缘为何物 的帖子
那个当然不是错误了,
都可以的,
查找路径不同……

2008-08-06 23:43
blueboy82006
Rank: 5Rank: 5
来 自:幻想世界
等 级:贵宾
威 望:16
帖 子:1227
专家分:57
注 册:2007-7-23
收藏
得分:0 
sum[i]=stud[i].score[0],+stud[i].score[1]+stud[i].score[2]+stud[2];
//这行严重错误……

2008-08-06 23:45
blueboy82006
Rank: 5Rank: 5
来 自:幻想世界
等 级:贵宾
威 望:16
帖 子:1227
专家分:57
注 册:2007-7-23
收藏
得分:0 
都是些小错啊,
你的编绎器不报错吗?
自己对照着改一下吧……

2008-08-06 23:46
缘为何物
Rank: 1
等 级:新手上路
帖 子:34
专家分:4
注 册:2008-8-6
收藏
得分:0 
嗯,学起来,嘿嘿…谢谢
2008-08-06 23:55
adam1600
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2008-3-1
收藏
得分:0 
[bo][un]缘为何物[/un] 在 2008-8-6 23:40 的发言:[/bo]

貌似第一行就出错了,不是应该用那个号括起来的?我刚学一天,不知道对不对,请指教。



在这里可以用<>,也可以用""了
2008-08-07 00:41
eagle8810
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-8-5
收藏
得分:0 
我修改的结果:
#include "stdio.h"
#define SIZE 5
typedef struct student
{
    char name[10];
    int num;
    int score[3];
    float ave;
}student,*st;
student stud[SIZE];
void save(void)
{
    FILE *fp;
    int i;
    if((fp=fopen("stu.dat","wb"))==NULL)
    {
        printf("The file can not open\n");
        return;
    }
    for(i=0;i<SIZE;i++)
    {
        if(fwrite(&stud[i],sizeof(struct student),1,fp)!=1)
        {
            printf("file write error\n");
            return;
        }
    }
    fclose(fp);
    return;
}
void main()
{
    int i;
    float sum[SIZE];
    FILE *fp1;
    for(i=0;i<SIZE;i++)
    {
        scanf("%s %d %d %d %d",&stud[i].name,&stud[i].num,&stud[i].score[0],&stud[i].score[1],&stud[i].score[2]);
        sum[i]=stud[i].score[0]+stud[i].score[1]+stud[i].score[2];
        stud[i].ave=sum[i]/3;
    }
    save();
    fp1=fopen("stu.dat","rb");
    printf("\n name    No   score1 score2 score3 ave\n");
    printf("----------------------------------------\n");
    for(i=0;i<SIZE;i++)
    {
        fread(&stud[i],sizeof(struct student),1,fp1);
        printf("%-10s %3d %7d %7d %7d %8.2f\n",stud[i].name,stud[i].num,stud[i].score[0],stud[i].score[1],stud[i].score[2],stud[i].ave);
    }
    fclose (fp1);
}

VC2008调试通过
2008-08-07 14:30
快速回复:请大家看看我这个程序错在那里
数据加载中...
 
   



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

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