파일 처리 학생정보 출력 질문입니다 ㅜㅜ
글리슨
왜 글자가 깨질까요 ㅜㅜ#include stdio.h
#include stdlib.h
#include string.hstruct personscore
{
int number;
char name[40];
int mid;
int final;
int quiz;
};
typedef struct personscore pscore;void printhead();
void printscore(FILE *f);
void writescore(FILE *f, int cnt);
int main()
{
char fname[] = score.bin; //파일 이름 저장소
FILE *f;
int cnt=0;
int re;
while(1)
{
printf(입력 );
scanf(%d, &re);
if(re==1)
{
if((f=fopen(fname, w))==NULL)
{
printf(파일이 없습니다\n);
exit(1);
};
writescore(f, cnt);
}else if(re==2)
{
if((f=fopen(fname, r))==NULL)
{
printf(파일이 없습니다\n);
exit(1);
};
printscore(f);
}else
break;
}return 0;
}void printhead()
{
printf(\n현재의 성적 내용은\n);
fprintf(stdout, %s\n, ------------------------------------------------------------------------------);
fprintf(stdout, %6s%18s%8s%8s%8s\n, 번호, 이름, 중간, 기말, 퀴즈);
fprintf(stdout, %s\n, ------------------------------------------------------------------------------);
}void printscore(FILE *f)
{
pscore score;
rewind(f);
printhead();
fread(&score, sizeof(pscore), 1, f);
while(!feof(f))
{
fprintf(stdout, %6d%18s%8d%8d%8d\n, score.number, score.name, score.mid, score.final, score.quiz);
fread(&score, sizeof(pscore), 1, f);
}
fprintf(stdout, %s\n, ------------------------------------------------------------------------------);
fclose(f);
}void writescore(FILE *f, int cnt)
{
pscore score;
char line[80];
printf(이름과 성적(중간, 기말, 퀴즈)을 입력하세요\n);
fgets(line, 80, stdin);
while(!feof(stdin))
{
sscanf(line, %s %d %d %d, score.name, &score.mid, &score.final, &score.quiz);
score.number = ++cnt;
fwrite(&score, sizeof(pscore), 1, f);
fgets(line, 80, stdin);
}
fclose(f);
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692343 | scnaf에 자꾸 선언을 참조하라는데;; (8) | 도래 | 2025-04-22 |
2692282 | 도스상에서 생성된 exe파일에 press~ 뜨게 하기 (4) | 회사원 | 2025-04-21 |
2692256 | scanf("%*c"); ㅠㅠ 고수님들 | 거북이 | 2025-04-21 |
2692230 | 하노이탑 질문입니다. (1) | 미쁘다 | 2025-04-21 |
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |