파일을 정렬하는 내용 질문이요
미즈
질문 제목 : 파일을 순위, 번호 점수순으로 정렬하는 문젠데요...순위와 점수정렬은 되는데 번호정렬을 못하겠어요. 여기서 번호는 파일이 처음 있던 순서로요.
번호는 점수를 88, 10, 75 라고 파일에 입력한걸 불러오면1번은 88,2번은 10, 3번은 75가 되는 거예요.질문 내용 :
#include stdio.h
#include stdlib.h
int *score;
int main()
{
void bubble_sort(int [], int no);
int i, n, m; //여기서번호를 m이라고 정하면
file *fp_in, *fp_out;
fp_in = fopen(score.txt, r);
if(fp_in == null) {
printf(file open error\n);
exit(1);
}
fp_out = fopen(stat.txt, w);
fscanf(fp_in, %d, &n);
score = (int *)malloc(n*sizeof(int));
for(i=0; in; i++)
fscanf(fp_in, %d, &score[i]);
bubble_sort(score, n);
printf(순위 번호 점수\n );
fprintf(fp_out, 순위 번호 점수\n );
for (int i=0; in; i++)
{
printf(%d %d %d \n , i+1, m, score[i]);
fprintf(fp_out, %d %d %d \n , i+1, m, score[i]);
}
fclose(fp_in);
fclose(fp_out);
free(score);
system(pause);
return 0;
}
void bubble_sort(int a[], int no)
{
int i, j, tmp;
for(i=no-1; i=1; i--) {
for (j=0; ji; j++)
if(a[j]a[j+1]) {
tmp=a[j];
a[j]=a[j+1];
a[j+1]= tmp;
}
}
}
여기에서 아무리 해도 순위하고 점수, 점수하고 순위는 출력이 가능한데 순위, 번호 , 점수는 아무리 해도 안되네요.
순위 번호 점수 이렇게 나오게 좀 해주세요
1 188
2 3 75
3210