|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
为什么我感觉我没有成功读入数据,哪里出了问题?顺便提示一些后面怎么排序呢?
- #include<stdio.h>
- #include<stdlib.h>
- struct student
- {
- int number;
- char name[4];
- double score[3];
- };
- int main()
- {
- struct student stu[10]; int i,j; double ave[10];
- FILE *fp1, *fp2;
- if( (fp1=fopen("student1.txt","r"))==NULL){
- printf("The file cannot open");
- exit(0);
- }
- for(i=0;i<10;i++){
- fread(stu,sizeof(struct student),1,fp1);
- }
- rewind(fp1);
- for(i=0;i<10;i++){
- for(j=0;j<3;j++){
- ave[i]=ave[i]+stu[i].score[j];
- }
- }
- fclose(fp1);
- return 0;
- }
复制代码
你的程序没有输出,你怎么知道,自己执行的对还是错?
Line 18:
要么没有循环, 改成 fread(stu,sizeof(struct student),10,fp1);
要么有循环,改成 fread(&stu[i],sizeof(struct student),1,fp1);
Line 23:
使用了未初始化的 ave
|
|