Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过fscanf读取文件并保存到int数组_C_Arrays_File_Int_Scanf - Fatal编程技术网

通过fscanf读取文件并保存到int数组

通过fscanf读取文件并保存到int数组,c,arrays,file,int,scanf,C,Arrays,File,Int,Scanf,我有一个a.txt文件,包括以下内容: A 50 60 70 B 80 90 100 我试图使用下面的代码将其保存到一个学生结构中,但它无法保存每个学生的最后两个成绩。 我已经打开了主文件。 请。有什么问题吗 typedef struct student{ char name[20]; int grades[3]; }student; while(fscanf(fp,"%s%d%d%d",stu[i-1].name,&stu[i-1].grades[0],

我有一个a.txt文件,包括以下内容:

A 50 60 70
B 80 90 100
我试图使用下面的代码将其保存到一个学生结构中,但它无法保存每个学生的最后两个成绩。 我已经打开了主文件。 请。有什么问题吗

 typedef struct student{
    char name[20];
    int grades[3];
    }student;


while(fscanf(fp,"%s%d%d%d",stu[i-1].name,&stu[i-1].grades[0],&stu[i-1].grades[1],&stu[i-1].grades[2])!=EOF)

1 stu后声明。2不要对其进行测试!=EOF但反对==4。3真正的问题在代码的其他地方-怀疑它在索引stu[]中。感谢您的帮助!问题是%s%d%d%d之间的空格。问题不是%s%d%d%d之间的空格。通过更改代码或输入的其他方面,您已经解决了问题。