파일 입출력에서 파일에 있는 글을 불러 오는거 좀 알려주세요~
하예
질문 제목 : 아래 프로그램에서 작성한 글을 텍스트로 저장하는거 까지 하였는데
다음번 실행하였을때 텍스트 파일에 있던 글을 불러와서 다시 작성후 다시 저장하고
다음에 또 불러오면 전에 저장하였던것이 나오도록 프로그램을 만드는겁니다;;;
근데 입력후 저장까지 하엿는데 다음 불러오기가 자꾸 막힙니다;;;;;;ㅠㅠ
질문 내용 :
#include stdio.h
typedef struct _student student;
struct _student
{
char name[16], id[16];
int kor, mat, eng, sum;
double avg;
};
?xml:namespace prefix = o /
void print_file(student *std)
{
int i;
file *outf;
outf = fopen(test1.txt,w);
for(i=0; i2; i++)
{
fprintf(outf, name[%d] : %s\n, i, std[i].name);
fprintf(outf, id[%d] : %s\n, i, std[i].id);
fprintf(outf, kor[%d] : %d\n, i, std[i].kor);
fprintf(outf, mat[%d] : %d\n, i, std[i].mat);
fprintf(outf, eng[%d] : %d\n, i, std[i].eng);
fprintf(outf, sum[%d] : %d\n, i, std[i].sum);
fprintf(outf, avg[%d] : %lf\n, i, std[i].avg);
}
fclose(outf); outf = null;
}
int main()
{
student std[10];
int i;
for(i=0; i2; i++)
{
printf(입력 : );
scanf(%s, std[i].name);
scanf(%s, std[i].id);
scanf(%d, &std[i].kor);
scanf(%d, &std[i].mat);
scanf(%d, &std[i].eng);
std[i].sum = std[i].kor + std[i].mat + std[i].eng;
std[i].avg = std[i].sum / 3.0;
}
print_file(std, 1);
}