Advertisement
deohay

mindigcsakatanulas

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