Advertisement
Guest User

bullshit

a guest
May 26th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. struct person
  7. {
  8.     char name[25];
  9.     int year, month, day;
  10. };
  11.  
  12. int hasonlit (const void *p1, const void*p2)
  13. {
  14. struct person f1 = *(const struct person *)p1;
  15. struct person f2 = *(const struct person *)p2;
  16.     if (f1.month > f2.month)
  17.     {
  18.         return -1;
  19.     }
  20.     if (f1.month < f2.month)
  21.     {
  22.         return 1;
  23.     }
  24.     if (f1.month == f2.month)
  25.     {
  26.         if (f1.day > f2.day)
  27.         {
  28.             return -1;
  29.         }
  30.         if (f1.day < f2.day)
  31.         {
  32.             return 1;
  33.         }
  34.         if (f1.day == f2.day)
  35.         {
  36.             return strcmp(f1.name,f2.name);
  37.         }
  38.     }
  39.     return 0;
  40. }
  41.  
  42. struct person *foo(char *fajlnev, int evszam)
  43. {
  44.     FILE *f = fopen(fajlnev, "rb");
  45.     struct person pers;
  46.     struct person *tomb;
  47.     int db = 0;
  48.     while (fread(&pers, sizeof(pers),1,f) == 1)
  49.     {
  50.         if (pers.year == evszam)
  51.             ++db;
  52.     }
  53.     tomb = malloc( db*sizeof(pers)+1);
  54.     db = 0;
  55.     rewind(f);
  56.     while (fread(&pers, sizeof(pers),1,f) == 1)
  57.     {
  58.         if (pers.year == evszam)
  59.             tomb[db++] = pers;
  60.         tomb[db+1].year = -1000;
  61.     }
  62.     qsort (tomb,db, sizeof(pers), hasonlit);
  63.  
  64.     return tomb;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement