Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- struct person
- {
- char name[25];
- int year, month, day;
- };
- int hasonlit (const void *p1, const void*p2)
- {
- struct person f1 = *(const struct person *)p1;
- struct person f2 = *(const struct person *)p2;
- if (f1.month > f2.month)
- {
- return -1;
- }
- if (f1.month < f2.month)
- {
- return 1;
- }
- if (f1.month == f2.month)
- {
- if (f1.day > f2.day)
- {
- return -1;
- }
- if (f1.day < f2.day)
- {
- return 1;
- }
- if (f1.day == f2.day)
- {
- return strcmp(f1.name,f2.name);
- }
- }
- return 0;
- }
- struct person *foo(char *fajlnev, int evszam)
- {
- FILE *f = fopen(fajlnev, "rb");
- struct person pers;
- struct person *tomb;
- int db = 0;
- while (fread(&pers, sizeof(pers),1,f) == 1)
- {
- if (pers.year == evszam)
- {
- db++;
- }
- }
- tomb = malloc( db * sizeof(pers) + 1);
- db = 0;
- rewind(f);
- while (fread(&pers, sizeof(pers),1,f) == 1)
- {
- if (pers.year == evszam)
- {
- tomb[db++] = pers;
- }
- }
- qsort (tomb,db, sizeof(pers), hasonlit);
- tomb[db+1].year = -1000;
- return tomb;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement