使用C写的程序,不知错在哪了,指教!

cava_she 2004-11-24 08:54:08
#include "stdio.h"
struct student{
int No;
char Name[8];
int Score[3];
float Avr;
} stu[3];
main()
{ int i;

FILE*fp;
printf("\nPlease input No. Name Score1,score2,score3:\n");

for (i=0;i<3;i++){
printf("StuNo:");
scanf("%d",stu[i].No);
printf("StuName:");
scanf("%s",stu[i].Name);
printf("StuScore1:");
scanf("%d",stu[i].Score[0]);
printf("StuScore2:");
scanf("%d",stu[i].Score[1]);
printf("StuScore3:");
scanf("%d",stu[i].Score[2]);
stu[i].Avr=(stu[i].Score[0]+ stu[i].Score[1]+stu[i].Score[2])/3.0;
}
fp=fopen("stud.txt","a+");
for(i=0;i<3;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error!\n");
fclose(fp);
}
...全文
186 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
pacman2000 2004-11-25
  • 打赏
  • 举报
回复
呵呵! 还是地址,指针的问题啊。
cava_she 2004-11-25
  • 打赏
  • 举报
回复
复:tokyji(热动火焰) :定义的score是数组
cava_she 2004-11-25
  • 打赏
  • 举报
回复
明白了,我用的Win_TC,编译没有错误,但是显示的时候就会有问题,只能打印name,刚刚看了 herryhuang(Herry)的提示,我知道这东西,但不是很熟练,用的时候就会大意,想不到它的存在,各位大侠,在下受教了。
程序的写法是太乱,一开始只是功能问题,至于其他的,其次吧
yu2680020 2004-11-25
  • 打赏
  • 举报
回复
最好把警告贴出来
Edenya 2004-11-25
  • 打赏
  • 举报
回复
最好每次都把编译后提示的错误也给大家展示出来,这样,这些高手改时就方便多了!!
tsingien 2004-11-25
  • 打赏
  • 举报
回复
很多时候警告就说明存在严重的问题。指针也好地址也好,在c里面和整数有什么区别吗?不做类型检查的话什么错误都没有。但是能通用吗?
tokyji 2004-11-24
  • 打赏
  • 举报
回复
int Score[3];定义有错!改成int Score;或char Score[3];

相应的主程序部分也要进行修改!
scanf("%d",stu[i].Score[0]);严重错误!
herryhuang 2004-11-24
  • 打赏
  • 举报
回复
回去看看scanf的用法。再看看数组和指针。
carylin 2004-11-24
  • 打赏
  • 举报
回复
#include "stdio.h"
struct student{
int No;
char Name[8];
int Score[3];
float Avr;
} stu[3];
main()
{ int i;

FILE*fp;
printf("\nPlease input No. Name Score1,score2,score3:\n");

for (i=0;i<3;i++){
printf("StuNo:");
scanf("%d",&stu[i].No);//
printf("StuName:");
scanf("%s",stu[i].Name);
printf("StuScore1:");
scanf("%d",&stu[i].Score[0]);//
printf("StuScore2:");
scanf("%d",&stu[i].Score[1]);//
printf("StuScore3:");
scanf("%d",&stu[i].Score[2]);//
stu[i].Avr=(stu[i].Score[0]+ stu[i].Score[1]+stu[i].Score[2])/3.0;
}
fp=fopen("stud.txt","a+");
for(i=0;i<3;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error!\n");
fclose(fp);
}
helanshan 2004-11-24
  • 打赏
  • 举报
回复
能编译啊,没有大的错误啊,只有两个警告错...
uglystone 2004-11-24
  • 打赏
  • 举报
回复
scanf("%d",&stu[i].No);
scanf("%d",&stu[i].Score[0]);
..
tianhxk 2004-11-24
  • 打赏
  • 举报
回复
是这里出错了 scanf("%d",& vairable);
scanf("%d",stu[i].No);---->scanf("%d",&stu[i].No);
--

#include "stdio.h"
struct student{
int No;
char Name[8];
int Score[3];
float Avr;
} stu[3];
main()
{ int i;

FILE *fp;
printf("\nPlease input No. Name Score1,score2,score3:\n");

for (i=0;i<3;i++){
printf("StuNo:");
scanf("%d",&stu[i].No);
printf("StuName:");
scanf("%s",&stu[i].Name);
printf("StuScore1:");
scanf("%d",&stu[i].Score[0]);
printf("StuScore2:");
scanf("%d",&stu[i].Score[1]);
printf("StuScore3:");
scanf("%d",&stu[i].Score[2]);
stu[i].Avr=(stu[i].Score[0]+ stu[i].Score[1]+stu[i].Score[2])/3.0;
}
fp=fopen("stud.txt","a+");
for(i=0;i<3;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error!\n");
fclose(fp);
}
imRainman 2004-11-24
  • 打赏
  • 举报
回复
#include "stdio.h"
struct student{
int No;
char Name[8];
int Score[3];
float Avr;
} stu[3];
main()
{ int i;

FILE*fp;
printf("\nPlease input No. Name Score1,score2,score3:\n");

for (i=0;i<3;i++){
printf("StuNo:");
scanf("%d",&stu[i].No);
printf("StuName:");
scanf("%s",stu[i].Name);
printf("StuScore1:");
scanf("%d",&stu[i].Score[0]);
printf("StuScore2:");
scanf("%d",&stu[i].Score[1]);
printf("StuScore3:");
scanf("%d",&stu[i].Score[2]);
stu[i].Avr=(stu[i].Score[0]+ stu[i].Score[1]+stu[i].Score[2])/3.0;
}
fp=fopen("stud.txt","a+");
for(i=0;i<3;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error!\n");
fclose(fp);
}

69,364

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧