
#include <stdio.h>
#include <stdlib.h>

//finds the number of students with student numbers greater than 1000
int findNumbers(int arr[], int size)
{
    int i;
    int count = 0;
    for(i=0; i<size; i++){
        if(arr[i] > 1000){
            count++;
        }
    }

    return count;
}

int main(int argc, char** argv)
{
    struct Person
    {
        char lname[20];
        char fname[20];
        int id;
    };

    int i, j, N ;
    int par_counter = 0;
    struct Person* par = malloc(20 * sizeof(int));

    //loop through each file
    for(j=1; j<argc; j++){
        int size = 20 * j;
        par = realloc(par, size * sizeof *par);
        FILE *str = fopen( argv[j], "r") ;
        if (str==NULL) {
            perror(argv[j]) ;
            exit(-1) ;
        }

        fscanf( str, "%d\n", &N ) ;

        for ( i=0 ; i<20 ; i++ ) {
            /* %s reads up to the next white space... not suitable for names with spaces */
            fscanf( str, "%[^,],%[^,],B%08d\n", par[par_counter].lname, par[par_counter].fname, &(par[par_counter].id) );
            par_counter++;
        }

        fclose(str) ;
    }

    /* Access the array... */
    printf("%s, %s, B%08d\n", par[4].lname, par[4].fname, par[4].id) ;

    return 0;
}

