C언어 문자와 숫자가 섞인 파일을 배열에 입력하고 싶습니다 도와주세요
20141456 브라운 50 40 70 30 20
20111234 해밀턴 12 45 68 97 47
20091879 정혜리 45 78 54 35 21
20091456 김민지 47 12 23 34 45
20111789 정만득 12 45 56 97 85
이런 파일을 배열에 추가 하고 싶은데요
#include
#include
#define MAX_ROWS 7
#define MAX_COLS 12
void getData (FILE*infp,int table[][MAX_COLS]);
void outData (FILE*outfp,int table[][MAX_COLS]);
int main (void)
{
FILE*infp,*outfp;
int table [MAX_ROWS][MAX_COLS];
getData (infp,table);
outData (outfp,table);
fclose(infp);
fclose(outfp);
return 0;
}
void getData(FILE*infp,int table[][MAX_COLS])
{
infp= fopen("c:\\test\\stdmark.txt","r");
for(int row=0;row<12;row++)
{for(int col=0; col<7; col++)
{if(col==1)
fscanf(infp,"%s",table[row][1]);
else
fscanf(infp,"%d",table[row][col]);
}
}
return;
}
void outData(FILE*outfp,int table[][MAX_COLS])
{
outfp = fopen("c:\\test\\cal_average.txt","w");
for(int row=0;row<12;row++)
{for(int col=0; col<7; col++)
{if(col==1)
fprintf(outfp,"%s",table[row][1]);
else
fprintf(outfp,"%d\n",table[row][col]);
}
}
return ;
}
이렇게 해봣는데
뭐가 틀린 건지를 잘 모르겠어요..
구조체 배열로 만들어서 하시면 될 듯 합니다.
간단하게 해결 !!!
댓글 달기