Hi,
I am trying to read from a file into a structure but my program crashes immediatedly..I reckon the problem lies w/ the fscanf statement but I ain't sure..please check..thanks
A
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* Prototype Declarations */
typedef struct{ char* names;
int id;
int scores[5];
} STRUCT;
int fillStructure(STRUCT table[]);
int main(void)
{
STRUCT table[50];
int check;
check = fillStructure(table);
return 0;
}
int fillStructure(STRUCT table[])
{
FILE *fpnum;
STRUCT *pStu;
STRUCT *pLastStu;
pLastStu = table + 49;
// Opens lab5.txt
if (!(fpnum = fopen ("lab5.txt", "r")))
for(pStu = table; pStu < pLastStu; pStu++)
{
fscanf(fpnum, "%s %d %d %d %d %d %d", table->names, table->id, table->scores[0], table->scores[1],
table->scores[2], table->scores[3], table->scores[4]);
}
else
{
printf("\aError: Was Unable to Open File.\n");
return 1;
}
return 0;
}