weixin_39339221 2017-06-28 08:22 采纳率: 0%
浏览 986

C语言有关txt文件读取的问题,小白求问

#include
#include
#include

struct StuInfo
{
long id[20];
char name[20];
char sex;
long num[20];
float score;
}stu[50];

void Load()
{
int i;
struct StuInfo stu[50];
FILE*fp;
fp = fopen("StuInfo1.txt", "r");
if ((fp = fopen("StuInfo1.txt", "r")) == NULL)
{
printf("The file can't be opened.\n");
return 0;
}

for (i = 0; !feof(fp); i++)
{
    fscanf(fp,"%d%s%s%d%f", stu[i].id, stu[i].name, stu[i].sex, stu[i].num, stu[i].score);
    printf("%d%s%s%d%f", stu[i].id, stu[i].name, stu[i].sex, stu[i].num, stu[i].score);
}
fclose(fp);
student = i;
return stu;

}
int main()
{
Load();
}

txt文件是50行形如:3 man male 12345678903 9.7000
完全运行不了。求调教

  • 写回答

1条回答

  • 温良岁月 2017-06-28 08:35
    关注

    1.不知道是你粘贴的时候出问题了还是什么,你的include的头文件呢?
    2.student = i; 这个student 没定义过。
    这两个改了后程序可以跑起来

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog