isnt everything where it should be, why the segmentation fault?


char *firstName[50];

firstName is array of 50 character pointer, and if you want to store anything into each of these char pointer, you need to allocate memory for them. For e.g

for (int counter = 0; counter < 10; counter ++) {
        firstName[counter] = malloc(SIZE_FIRST); /* memory allocated for firstName[counter], now you can store into it */ 
        lastName[counter] = malloc(SIZE_LAST);           
        fscanf(config, "%s %s\n", firstName[counter], lastName[counter]);

Once done with processing of firstName and lastName free the dynamically allocated memory to avoid memory leakage.

Browse More Popular Posts

Leave a Comment