Advertisement
zsoltizbekk

asdqwe

May 19th, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct elem
  6. {
  7.   int sorszam;
  8.   char nev[ 36 ];
  9.   int pontszam;
  10. }ELEM;
  11.  
  12. int rendez (const void *a, const void *b)
  13. {
  14.     ELEM *pa=(ELEM *)a;
  15.     ELEM *pb=(ELEM *)b;
  16.    
  17.     if (pa->pontszam < pb->pontszam) return 1;
  18.     if (pa->pontszam > pb->pontszam) return -1;
  19.     if (pa->pontszam == pb->pontszam){
  20.         if (pa->sorszam > pb->sorszam)
  21.             return 1;
  22.         if (pa->sorszam < pb->sorszam)
  23.             return -1;
  24.     }
  25. }
  26.  
  27. int main(int argc, char *argv[])
  28. {
  29.     FILE *be, *ki;
  30.     be=fopen(argv[1], "r");
  31.     ki=fopen(argv[2], "wb");
  32.     int i=0;
  33.     char *tok;
  34.     char sor[81];
  35.     while (fgets(sor, 81, be))
  36.         i++;
  37.  
  38.     ELEM t[i];
  39.  
  40.     rewind(be);
  41.  
  42.     while (fgets(sor, 81, be)){
  43.         t[i].sorszam=i+1;
  44.         tok=strtok(sor, ";");
  45.         strcpy(t[i].nev, tok);
  46.         tok=strtok(NULL, ";");
  47.         t[i].pontszam=atoi(tok);
  48.         while (tok=strtok(NULL, ";")){
  49.             t[i].pontszam=t[i].pontszam+(atoi(tok));
  50.         }
  51.         i++;
  52.     qsort(t, db, sizeof(ELEM), rendez);
  53.    
  54.    
  55.        
  56.     }
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement