我正在做的实验的一个要求是我从已经给出的输入文件中屏蔽学生数字的前3个数字。
我给出的文件如下:
1016807 89.0 93.0 78.0 50.0
1211272 84.0 78.0 23.0 59.0
1564440 85.0 82.0 22.0 37.0
如果数字列是学号,则是作业/实验/期中/考试成绩。
我找不到任何其他方法来替换每行中的前3个数字,因此我使用的是for
循环,其中包括:
fseek(inFile, 3, SEEK_CUR);
fscanf(inFile, "%d %f %f %f %f", &number, &homework, &lab, &midterm, &exam);
weightHomework = 0.10*homework;
weightLab = 0.20*lab;
weightMidterm = 0.30*midterm;
weightExam = 0.40*exam;
if (midterm > exam)
total = weightHomework + weightLab + weightMidterm + weightExam;
else total = weightHomework + weightLab + (exam * .30) + weightExam;
fprintf(outFile,"xxx%d %f %f %f %f %f\n", number, homework, lab, midterm, exam, total);
使列在输出文件中对齐所需的奇怪缩进和间距。
当我打开输出文件时,它显示为:
SN Homework Lab Midterm Exam Total
xxx6807 89.000000 93.000000 78.000000 50.000000 70.900002
xxx1211272 84.000000 78.000000 23.000000 59.000000 65.300003
xxx1564440 85.000000 82.000000 22.000000 37.000000 50.799999
这告诉我fseek
函数(正确的单词?新手,对不起)只能使用一次。如何在最后两次迭代中使其工作?谢谢!