|
FILE *fp = fopen("c:\\data.txt", "wt");
for(i=0;i<1;i++)
{
fprintf(fp,"이름 학번 국어 영어 수학 평균 \n");
st[i].avg=average(st[i].total);
fprintf(fp, "%-8s %s %3d %3d %3d %4f\n",st[i].name,st[i].no,st[i].kor,st[i].eng,st[i].math,st[i].avg);
}
fclose(fp);
김진훈 님이 쓰신 글 :
: FILE *fp를 써서 아래프로그램 결과를 txt화일로 출력해야 하는데 안되네요.
: fprintf()함수를 이용하는데 잘 안돼요..어떤 방법이 있는지요???
:
: #include<stdio.h>
: struct score {
: char name[10];
: char no[4];
: int kor;
: int eng;
: int math;
: int total;
: float avg;
: };
: struct score st[10]; /*구조체 변수 st 선언*/
: float average(int total); /*평규값 avg함수의 선언 */
:
: main()
: {
: int i;
: int total;
: float avg;
: for(i=0;i<1;i++)
: {
: int k;
: k=i+1;
: printf("\n enter %dth stduent's name, no and score orderly manner",k);
: printf("\n input student's name(not permitted space): ");
: scanf("%s",&st[i].name);
: printf("\n input his(her) number : ");
: scanf("%s",&st[i].no);
: printf("\n input his(her) korean score : ");
: scanf("%d",&st[i].kor);
: printf("\n input his(her) english score : ");
: scanf("%d",&st[i].eng);
: printf("\n input his(her) mathematic score : ");
: scanf("%d",&st[i].math);
: st[i].total=st[i].kor+st[i].eng+st[i].math;
: }
: printf("\n\n");
: for(i=0;i<1;i++)
: {
: printf("이름 학번 국어 영어 수학 평균 \n");
: st[i].avg=average(st[i].total);
: printf("%-8s %s %3d %3d %3d %4f\n",st[i].name,st[i].no,st[i].kor,st[i].eng,st[i].math,st[i].avg);
: }
: }
:
:
: float average(int total) /*평균값 avg함수의 정의*/
: {
: return total/3.0;
: }
:
|