Reading from File and Storing into Array
Code:
void function2 (void)
{
FILE *in;
char var;
int lab [MAX];
float test1, test2;
int i = 0;
if (( in = fopen ("grades.txt", "r")) == NULL)
{
printf ("Error Opening File");
return;
}
while ((fscanf(in, "%c", &var)) != EOF)
{
if (var == ':')
fscanf (in, "&d", &lab[MAX]);
}
printf ("%d",&lab[1]);
}
The .txt file I opened has the following:
Code:
Lab 1: 10
Lab 2: 18
Lab 3: 22
Lab 4: 19
Lab 5: 14
Lab 6: 16
Lab 7: 18
Lab 8: 18
Exam 1: 65
Exam 2: 42
When I test, I should expect it to print "10" after printing the entire .txt to screen.
It does not do this.