【发布时间】:2012-11-27 10:10:18
【问题描述】:
我一直在试图弄清楚如何读取分数并将它们存储在数组中。 已经尝试了一段时间,它显然不适合我。请帮忙。
//ID scores1 and 2
2000 62 40
3199 92 97
4012 75 65
6547 89 81
1017 95 95//.txtfile
int readresults (FILE* results , int* studID , int* score1 , int* score2);
{
// Local Declarations
int *studID[];
int *score1[];
int *score2[];
// Statements
check = fscanf(results , "%d%d%d",*studID[],score1[],score2[]);
if (check == EOF)
return 0;
else if (check !=3)
{
printf("\aError reading data\n");
return 0;
} // if
else
return 1;
【问题讨论】:
-
你会一直知道你会读多少乐谱吗?如果没有,那么您将需要使用 WHILE 循环,直到完成。您打算多次调用此函数(每个玩家一次)还是只调用一次?
-
是的,总是学生 ID 和分数 1 和分数 2。最多 50 分超出我将不得不打印一条消息,例如“该文件包含超过 50 名学生!”并终止程序。
-
@KexyKathe:他的意思是,是否设置了行数;在这种情况下 5. 此外,如果您在此处编写的文件中有标题,则也需要注意它 - 读取并丢弃。
-
.txt 文件只包含数字。