I am trying to write a program that reads a file into an array of structs. I decided to see if this aspect worked before expanding on the program. Here's the code:
list.dat is just a file that has a list of words, likeCode:#include<stdio.h> struct analg { char word[6]; char signature[6]; }; int main() { analg h[106]; FILE *fp; int i; fp = fopen("list.dat", "r"); if(fp == NULL) { printf("CANNOT OPEN FILE. PROGRAM EXITING"); return 1; } else { for(i=0; i<106; i++) { while(fgets(h[i].word, 6, fp){ printf("%s", h[i].word); } } } fclose(fp); return 0; }
throw
timer
tones
tower
trace
trade
tread
Entered exactly like that. When I try to compile the program, I get several errors, and I was wondering what I was doing wrong.