Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Magas szintű programozási nyelvek 1, 2015. május 20., Sz12 ZH
- * mindigcsakatanulas
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- struct tanulok{
- char nev[41];
- int igaz;
- };
- int main(int argc, char *argv[]){
- FILE *f=fopen(argv[1], "r");
- struct tanulok *tomb;
- char c;
- char *sor;
- char *p;
- int db=0, maxsor=0, hossz=0, igazdb=0, i;
- while((c=fgetc(f))!=EOF){
- db++;
- fseek(f, -1, SEEK_CUR);
- hossz=0;
- while((c=fgetc(f))!=EOF && c!='\n')
- hossz++;
- if(hossz>maxsor)
- maxsor=hossz;
- }
- tomb=malloc(db*sizeof(struct tanulok));
- sor=malloc(maxsor*sizeof(char));
- rewind(f);
- db=0;
- while((c=fgetc(f))!=EOF){
- fseek(f, -1, SEEK_CUR);
- hossz=0;
- while((c=fgetc(f))!=EOF && c!='\n')
- sor[hossz++]=c;
- igazdb=0;
- p=strtok(sor, ";");
- strcpy(tomb[db].nev, p);
- p=strtok(NULL, ";");
- while(p!=NULL){
- if(p[0]=='I'){
- tomb[db].igaz=1;
- }
- p=strtok(NULL, ";");
- }
- db++;
- }
- for(i=0; i<db; i++)
- if(tomb[i].igaz==1)
- igazdb++;
- printf("%d\n", igazdb);
- for(i=0; i<db; i++)
- if(tomb[i].igaz==1)
- puts(tomb[i].nev);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement