早教吧作业答案频道 -->其他-->
如何将下列数据读出并赋值给结构体数组?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);
}
}
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;//...
看了如何将下列数据读出并赋值给结构...的网友还看了以下:
1/2{1/2[1/2(1/2y-3)-3]-3}=17x-1/0.024=1-0.2x/0.08 2020-04-27 …
问个节点电压方程如图我给出的方程是(1/8+1/2.5+1/4)un1-1/2.5un2-1/4u 2020-05-14 …
(1)1/1*2+1/2*3+.+1/2009*2010(2)1/2*4+1/4*6+.+1/20 2020-05-17 …
6÷3/8–3/8÷64/7×5/9+3/7×5/95/2-(3/2+4/5)7/8+(1/8+1 2020-07-18 …
用3、5、3、7、1、8、3、1、2这几个数按顺序算出1、11、111、1111我只算出2个……算 2020-07-26 …
初一一道数学找规律的题急用1.将1,-1/2,1/3,-1/4,1/5,-1/6,.按一定的规律排列 2020-11-03 …
计算,并写出过程.例:3分之2-8分之1[-3分之1]+[-8分之3]3分之2-8分之1[-3分之1 2020-11-07 …
求助1/2*4+1/4*6+1/6*8+…+1/2010*2012=1/2(1/2-1/4+1/4- 2020-11-07 …
直接写出得数6.3÷9=4.2÷2.1=8-2.6=4×1.5=0.32+0.8=1.7+0.25= 2020-11-19 …
(1/8+1/9+1/10+1/11)*(1/9+1/10+1/11+1/12)-(1/8+1/9+ 2020-12-01 …