这是一段代码。基本上,它是在第一个“while”部分计算列表中的学生数量,而不是根据计数分配。并将其保存到struct。 但问题是:首先“while”作为无限循环运行?
int t=0;
FILE *exam;
struct str_examrecords_table
{
int id_number;
char result;
};
void Load_examrecords_table(struct str_examrecords_table *examrecords_table)
{
char temporary_char;
int temporary_int, i=0;
exam=fopen("examrecords.odt","r");
if(exam!=NULL)
{
while(fscanf(exam, "%d %c", &temporary_int, &temporary_char)!=EOF)
t++;
examrecords_table = (struct str_examrecords_table *) malloc(sizeof(struct str_examrecords_table) * t);
while(fscanf(exam, "%d %c", &examrecords_table[i].id_number, &examrecords_table[i].result)!=EOF)
i++;
}
else exit(1);
for(int j=0; j<i; j++)
printf("%d %c \n", examrecords_table[i].id_number, examrecords_table[i].result);
fclose(exam);
}
int main()
{
struct str_examrecords_table *examrecords_table;
Load_examrecords_table(examrecords_table);
system("pause");
return 0;
}