【发布时间】:2016-03-18 09:35:48
【问题描述】:
让我的循环在结束后停止读取文件时遇到问题。如何让它在最后一行之后停止并转到下一行代码?另外我希望增加的分数随着循环停止并将最终结果写入文件,有人可以帮忙吗?谢谢
do {
system("cls");
i = 0;
printf("\tPortal Examination\n\tEnter Faculty name.:");
fflush(stdin);
scanf("%s", f_name);
printf("\n\tEnter Course.:");
fflush(stdin);
scanf("%s", course_text);
printf("\n\tEnter ID.:");
fflush(stdin);
scanf("%s", r_query);
k = strlen(r_query);
strcat(f_name,"101stud.txt");
strcat(course_text,"101exam.txt");
f_course = fopen(f_name, "rb");
system("cls");
printf("\tPortal Examination");
printf("\n\n..:: Searching for '%s' \n===================================================\n",r_query);
while (fread(&stud, sizeof(stud), 1, f_course) == 1) {
for (j = 0; j <= k; j++) {
s_rollno[j] = stud.stud_rollno[j];
}
s_rollno[j]='\0';
if (stricmp(s_rollno,r_query) == 0) {
system("pause");
//*****write exams****
f_exam = fopen(course_text, "rb");
while (fread(&numbers, sizeof(numbers), 1, f_exam) != EOF) {
system("cls");
printf("\n\tAnswer all Questions:\n\t%s\n\t",numbers.question);
fflush(stdin);
scanf("%s", a_query);
if (stricmp(numbers.answer, a_query) == 0)
s_result += 5;
printf("%s has %d score\n\t", r_query, s_result);
system("pause");
}
break;
i++;
if (i % 4 == 0) {
printf("..::Press any key to continue...");
getch();
}
}
}
if (i == 0)
printf("\n..::No match found!");
else
printf("\n..:: %d match(s) found.",i);
fclose(f_course);
printf("\n..:: Search Again?\n\n\t[1] Yes\t\t[0] No\n\t");
scanf("%d",&ch);
} while (ch == 1);
break;
【问题讨论】:
标签: c loops eof file-handling