本文介绍了停止的fscanf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在写学校一年级的书计划,我感到困惑的一件事。我们有一个文件从具有多个学生ID和多个分数来读取。请问这样做:
=结果的fscanf(成绩册,%D%D,ID,SCO1,SCO2,sco3);
存储号码到这些变量,因为它读取然后停止光标当它运行的变量来存储中的信息?......那么我应该直接进入计算功能面前来计算最终成绩是循环的fscanf下一个学生?
=结果的fscanf(成绩册,%D%D,ID,SCO1,SCO2,sco3);
getCalc(SCO1,SCO2,sco3);
是允许的?谢谢你的帮助。
解决方案
No, unless it is in a while loop, it stops exactly after reading the four entries ONCE, unless you are using the value from results
to control a while loop and call fscanf() multiple times to scan 4 entries at every call.
Example:-
//Keeps reading unless it encounters less than 4 parameters, which might be the case
//if an end of file is reached, or your data pattern changes.
while( fscanf(gradebook, "%d %d %d %d", id, sco1, sco2, sco3) == 4 )
{
//You can pass the data of individual id, to calculate function, and compute the required
//sum, total or other data locally in the function, there is really no reason to use pass
//address in your case, so just transfer data using pass by value method.
getCalc(id,sco1,sco2,sco3);
}
这篇关于停止的fscanf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!