I am reading in a txt file into an array - programData[100][6] from Main. I cannot change the element sizes per specs. Is the newline char even being saved since ALL words being read in are 5 characters long. Thus fgets() sees the newline from the txt file in the 6th position and appends a '\0' to the 6th position (over the newline) because the array size is only 6. So maybe I do not need to append my own '\0' char to the end since it would seem fgets() is doing that for me. So how to I get fptr to advance to the next line???? It seems that fgets is pausing on the first line on the second call and then advancing on the third call, this might be why counter when printed out shows 127 and then I get a seg fault since counter is integrated into fgets() and I've exceeed the array bounds. Any help appreciated. Thanks!!!
Code:void readFileIntoArray(char programData[][6]) { FILE *fptr; int counter = 0; fptr = fopen("a:\\269data.txt","r"); if (fptr == '\0') { printf("*****269data.txt file error - aborting program!*****\n"); system("pause"); exit(0); } if(feof(fptr)) { printf("*****No data to read!*****\n"); system("pause"); } printf("\n\nTable 1 Initial Program Data as Read from 269data.txt...\n\n"); while(!feof(fptr)) { fgets(programData[counter],6,fptr); programData[counter][6-1] = '\0'; //This doesn't work and I get a seg fault counter++; //counter seems to pass 100 and stops at 127 before crash } }