Yeah so I have coded this really simple program using one structure, with the information being scaned in to the structure from a seperate file called poeple.dat.
Within my master while loop im printing the character array g1.names[i]. For some reason I cant figure out, I am getting a segmentation fault after exiting the master while loop. All information is scaned in successfully yet the program always ends in a segmentation fault.
My code is this
Code:#include <stdio.h> #define FILENAME "poeple.dat" struct building { char names[100]; int var1, var2, var3, var4; }; int main(void) { struct building g1; FILE *people; int i=0; char letter; people = fopen(FILENAME, "r"); while((letter=fgetc(people))!=EOF) { g1.names[i]=letter; i++; while(letter!='\t') { letter=fgetc(people); g1.names[i]=letter; i++; } g1.names[i]=0; fscanf(students,"%i%i%i%i",&g1.var1, &g1.var2, &g1.var3, &g1.var4); i=0; printf("%s",g1.names); } fclose(people); return(0); }
my output always looks like this
Ive rebuilt this code many times and completely analysed this code but cant figure out for the life of me whats wrong.Code:Erezah Erez Kriehn Bel Bzammm Tester Testah Segmentation fault
any help would bo much appreciated, thanks.



LinkBack URL
About LinkBacks


