1#include <stdio.h>2#include <string.h>3#include <stdlib.h>4 5 structperson{6 Char*Number ; 7 Char*name; 8 intscore; 9 }; Ten One intMain () A { - structPerson arr[5]; -FILE *FP = fopen ("src","R"); theFILE *FP1 = fopen ("dest","A +"); - if(NULL = =FP) - { -Perror ("fopen"); + return 1; - } + Char*line =NULL; A intLen =0, i =0, j =0; at Charpn[5][ -] = {0}; - - while((Getline (&line, &len, fp))! =-1) - { -j =0; - while(*line! ='\ n'){ in* (* (pn+i) +j) = *line++; -J + +; to } +i++; - } the * Char*str; $ intm =i;Panax Notoginseng Char*brr[3]; - Char*tmp; the for(i=0; i<m; i++) + { ATMP = * (pn+i); the for(j=0; j<3; J + +){ +str = STRSTR (TMP,"\ t"); -* (BRR+J) = Strtok (TMP,"\ t"); $TMP = str +1; $ } -Arr[i].number = * (brr+0); -Arr[i].name = * (brr+1); theArr[i].score = atoi (* (brr+2)); -printf"%s%s%d\n", Arr[i].number, Arr[i].name, Arr[i].score); Wuyi } the - structPerson ttmp; Wu for(i=0; i<m; i++) - { About for(j=i; j<m; J + +) $ { - if(Arr[i].score <Arr[j].score) - { -Ttmp =Arr[i]; AArr[i] =Arr[j]; +ARR[J] =ttmp; the } - } $ } the the Charshow[ -]; the for(i=0; i<m;i++){ theFputs (ARR[I].NUMBER,FP1); Fputs"\ t", FP1); -Fputs (ARR[I].NAME,FP1); Fputs"\ t", FP1); insprintf (Show,"%d", Arr[i].score); theFputs (SHOW,FP1); Fputs"\ n", FP1); the } About thefclose (FP); thefclose (FP1); the}
Write files after sorting