早教吧 育儿知识 作业答案 考试题库 百科 知识分享

如何将下列数据读出并赋值给结构体数组?a10011808182b10021508788c10031877675d10041888990e10051858482f10061888888g10071999999h100811008882i10091808620j1010110020100我自己写了一点

题目详情
如何将下列数据读出并赋值给结构体数组?
a 1001 1 80 81 82
b 1002 1 50 87 88
c 1003 1 87 76 75
d 1004 1 88 89 90
e 1005 1 85 84 82
f 1006 1 88 88 88
g 1007 1 99 99 99
h 1008 1 100 88 82
i 1009 1 80 86 20
j 1010 1 100 20 100
我自己写了一点程序,大神看看我程序哪里出了问题:
#include
void main()
{
struct student //定义一个结构体
{
char name;
int no;
int clas;
int yy;
int math;
int yw;
}stu[10],*p=stu;//定义结构体数组
FILE* pFile = NULL;
int i;
//!以“读”的方式打开文件
pFile = fopen("st.txt","r");
if (NULL = pFile)
{
for(p=stu;pname);
fscanf(pFile,"学号:%d\n",p->no);
fscanf(pFile,"班级:%d\n",p->clas);
fscanf(pFile,"英语成绩:%d\n",p->yy);
fscanf(pFile,"数学成绩:%d\n",p->math);
fscanf(pFile,"语文成绩:%d\n",p->yw);
}
fclose(pFile);
}
printf("输出成绩:\n");
for(i=0;iname);
printf( "学号:%d\n",p->no);
printf( "班级:%d\n",p->clas);
printf( "英语成绩:%d\n",p->yy);
printf( "数学成绩:%d\n",p->math);
printf( "语文成绩:%d\n",p->yw);
}
}
▼优质解答
答案和解析
//你对照一下吧,现在可以达到你的要求#includevoid main(){struct student //定义一个结构体{char name;int no;int clas;int yy;int math;int yw;}stu[10],*p=stu;//定义结构体数组FILE* pFile = NULL;int i;//...