학생 이름 중기 및 최종 점수를 받고 txt 파일에 쓰기를 원하지만 루프를 사용할 때 결코 학생 이름을 얻지 못합니다. 그것은 항상 그것을 놓친다. 루프에서 feof를 어떻게 사용할 수 있습니까? 중간 이름과 최종 점수를 얻고 점수를 통해 평균을 계산하고 싶습니다. 사용자가 파일의 끝을 누를 때까지 항상 이름과 점수를 얻어야합니다.while 루프와 함께 feof를 사용하려면 어떻게해야합니까?
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
FILE *Points;
char namesOfStudents[10];
int pointsOfStudents[1][2];
double AverageOfStudents[1];
int i=0,j=1;
int numberOfStudents;
Points = fopen("C:\\Users\\Toshiba\\Desktop\\PointsOfStudent.txt", "a+");
fprintf(Points, "Name\t\t 1.Grade\t2.Grade\t\tAverage\n");
/* printf("How many students will you enter: ");
scanf("%d",&numberOfStudents);*/
//while (!feof(Points))
printf("Please enter new students name: ");
gets(namesOfStudents);
printf("\nPlease enter new students first point: ");
scanf("%d",&pointsOfStudents[0][0]);
printf("\nPlease enter new students second point: ");
scanf("%d",&pointsOfStudents[0][1]);
for (; i < strlen(namesOfStudents); i++)
{
fprintf(Points, "%c", namesOfStudents[i]); //To write
student name to file
}
fprintf(Points,"\t\t ");
fprintf(Points,"%d\t\t",pointsOfStudents[0][0]); //to write
student's first point
fprintf(Points,"%d\t\t",pointsOfStudents[0][1]); //to write
student's second point
fprintf(Points,"%d\n",(pointsOfStudents[0][0]+pointsOfStudents[0]
[1])/2); //to calculate and write average
system("cls");
fclose(Points);
system("Pause");
}
[관련 질문] (http://stackoverflow.com/questions/5431941/why-is-while-feof-file-always-wrong?rq=1) – InternetAussie