Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- typedef struct orszag{
- char nev[100];
- int zaszlo;
- }ORSZAG;
- int cmp(const void *a, const void *b)
- {
- ORSZAG x = *((ORSZAG*) a);
- ORSZAG y = *((ORSZAG*) b);
- if((y.zaszlo-x.zaszlo)!=0) return y.zaszlo-x.zaszlo;
- else return (strcmp(x.nev, y.nev));
- }
- int main(int argc, char* argv[])
- {
- int orszag=0;
- FILE*f=fopen(argv[1],"r");
- char s[1000];
- while( fgets(s,1000,f) != NULL )
- {
- orszag++;
- }
- fseek(f,0,SEEK_SET);
- ORSZAG x[orszag];
- int i,max=0;
- int y1=0;
- while( fgets(s,1000,f) != NULL )
- {
- x[y1].zaszlo=0;
- strcpy(x[y1].nev,strtok(s,";"));
- while(strtok(NULL,";")!=NULL)
- {
- x[y1].zaszlo++;
- }
- if(x[y1].zaszlo>max)
- max=x[y1].zaszlo;
- y1++;
- }
- qsort(x, y1, sizeof(ORSZAG), cmp);
- for(i=0;i<y1;i++)
- {
- if(x[i].zaszlo==max)
- printf("%s\n",x[i].nev);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement