Whoa. Your fundamental misunderstanding of structs and how to use format strings with scanf functions is really killing you here.
I'm not sure where you are getting the number 100 or 50, but let's just assume that 50 is enough, that is, there are 50 or fewer records in the file.
So then you have an array of 50 student structs, and each struct has the member variables term, id, lname,...
fgets() reads 1 line at time from your file. Read the description of the function. So, each iteration of the while loop, you read 1 line of the file.
Then you use sscanf to break up that line (string) into the different fields, term, id, lname,... and store them into the member variables.
You don't just try to stuff a string into a struct - that just doesn't even make sense. I'll give you an example - but DONT just copy what I do. Understand what is going on and then apply it to your problem.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_NAME 30
#define BAR_MAX 5
#define REC_MAX 50
typedef struct foo FOO ;
struct foo{
int number ;
char name[MAX_NAME] ;
float score ;
} ;
int main()
{
int i = 0 ;
FOO bar[BAR_MAX] ;
char record[REC_MAX + 1] = {0};
FILE *fp ;
if( (fp = fopen("foo.txt", "r")) == NULL )
{
printf("Could not open foo.txt for reading.\n");
exit(1) ;
}
while( i < BAR_MAX && fgets( record, REC_MAX, fp ) )
{
sscanf( record, "%d: %[^:]: %f", &bar[i].number,
bar[i].name,
&bar[i].score ) ;
++i ;
}
for( i = 0; i < BAR_MAX; ++i )
printf("%5d %10s %3.1f\n", bar[i].number, bar[i].name, bar[i].score) ;
return 0 ;
}
With foo.txt
Code:
1:Frank:3.0
2: Bob: 2.1
3:Sue:4.0
4:Dave:3.2
5: Anne:2.9