Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "myheader.h"
- int rendez(const void *a, const void *b){
- struct country *pa = (struct country*)a;
- struct country *pb = (struct country*)b;
- if(pa->area > pb->area)
- return -1;
- if(pa->area < pb->area)
- return 1;
- if(pa->area == pb->area){
- return strcmp(pa->name,pb->name);
- }
- }
- struct country *foo(char *s, int ter, int nep){
- FILE *f;
- f = fopen(s,"rb");
- struct country orszag;
- struct country *orszagok;
- int db=0,i=0;
- int nepsuruseg;
- int ratio = nep/ter;
- while(fread(&orszag,sizeof(struct country),1,f)){
- nepsuruseg = orszag.population / orszag.area;
- if(nepsuruseg > ratio){
- db++;
- }
- }
- orszagok = malloc( (db+1)*sizeof(struct country));
- rewind(f);
- while(fread(&orszag,sizeof(struct country),1,f)){
- nepsuruseg = orszag.population / orszag.area;
- if(nepsuruseg > ratio){
- orszagok[i] = orszag;
- i++;
- }
- }
- qsort(orszagok,db,sizeof(struct country),rendez);
- orszagok[db].area = -1;
- fclose(f);
- return orszagok;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement