파일 출력을 구조체로 받을 때, 파일의 끝을 판별하는 방법을 알려주세요.

\
질문 제목 :파일 출력을 구조체로 받을 때, 파일의 끝을 판별하는 방법을 알려주세요.질문 요약 :파일 출력을 구조체로 받을 때, 파일의 끝을 판별하는 방법을 알려주세요.질문 내용 : 소스 아래에 빨간 부분 해법을 알려주세요.#include stdio.h
#include windows.h
#include string.h#define _name_size 30typedef struct {
char *name;
int kor;
int eng;
int mat;
} grade;void main()
{
int i;
FILE *fp, *cp;
grade *student = (grade *)malloc(sizeof(grade)*3); if((fp = fopen(.\\imsi.txt, r)) == NULL)
{
puts(no file found);
exit(0);
}
cp = fopen(.\\imsicp.txt, w); for(i = 0; fp != EOF; i++) //- fscanf(fp, %s %d %d %d, student[i].name, &student[i].kor, &student[i].eng, &student[i].mat)로 해도 안되고 fp로 해도 안되고 방법을 모르겠습니다!
파일 포인터가 파일의 끝을 감지시 자동으로 for나 while문을 탈출하게끔 하려면 어떻게 해야하나요?
{
student[i].name = (char *)malloc(_name_size);
fscanf(fp, %s %d %d %d, student[i].name, &student[i].kor, &student[i].eng, &student[i].mat);
printf(%s %d %d %d\n, student[i].name, student[i].kor, student[i].eng, student[i].mat);
} free(student-name);
free(student);
}

댓글 2

  • 보단 2026.10.17

    님은 천재입니다!! 어떤 문제가 또 생길지 모르겠지만 감사해요. ㅠㅠ

  • 해골 2026.10.17

    while(!feof(fp)) 해보시겠어요?

C언어 다른 글

목록