Advertisement
deohay

nyamnyam

May 27th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. /*
  7.  * nyamnyam
  8.  */
  9. struct allatok{
  10. char allat[40];
  11. int kalor;
  12. };
  13. int main(int argc, char *argv[]){
  14.  
  15. FILE *f=fopen(argv[1], "r");
  16. struct allatok *tomb;
  17. char c;
  18. int sorok=0, hossz=0, maxhossz=0, db=0, maxkal=0, i;
  19. int db2=0;
  20. char *sor;
  21. char *p;
  22.  
  23. while((c=fgetc(f))!=EOF){
  24.     sorok++;
  25.     fseek(f, -1, SEEK_CUR);
  26.     hossz=0;
  27.    
  28.     while((c=fgetc(f))!=EOF && c!='\n')
  29.         hossz++;
  30.  
  31.     if(hossz>maxhossz)
  32.         maxhossz=hossz;
  33. }
  34. tomb=malloc(sorok*sizeof(struct allatok));
  35. sor=malloc((maxhossz+1)*sizeof(char));
  36. rewind(f);
  37.  
  38. while((c=fgetc(f))!=EOF){
  39.     fseek(f, -1, SEEK_CUR);
  40.     db=0;    
  41.     while((c=fgetc(f))!=EOF && c!='\n'){
  42.         sor[db]=c;
  43.         db++;
  44.     }
  45. sor[db]='\0';
  46.  
  47. p=strtok(sor, ";");
  48. strcpy(tomb[db2].allat, p);
  49. p=strtok(NULL, ";");
  50. while(p!=NULL){
  51.     if(isdigit(p[0]))
  52.         tomb[db2].kalor=atoi(p);
  53.     p=strtok(NULL,";");
  54. }
  55. db2++;
  56. }
  57. fclose(f);
  58.  
  59. for(i=0; i<db2; i++)
  60. if(tomb[i].kalor>maxkal)
  61. maxkal=tomb[i].kalor;
  62. printf("%d\n", maxkal);
  63.  
  64. for(i=0; i<db2; i++)
  65. if(maxkal==tomb[i].kalor)
  66. puts(tomb[i].allat);
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement