Im trying to read some integers values from a text file.
The problem is that first lines of the text files contains some text and only then theres the values that i want to read into variables , and i dont know how to get down three lines and then read using fscanf .
TEXT FILE(storeinfo.txt):
Stores Information:
Store Code Store Size Store Workers Store Income
951 1200 7 67000
952 1452 12 92833
953 800 5 41000
954 1000 6 61000
955 1500 12 100321
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int code;
int size;
int workers;
int total;
}store;
int main()
{
int i;
FILE *filein;
char source[40];
store storearr[5]={0};
printf ("Enter a source filename: ");
gets(source);
filein = fopen (source,"rt");
if (filein == NULL)
{
printf ("Unable to open sourcefile...\n");
exit(1);
}
for (i=0;i<5;i++)
fscanf(filein,"%d %d %d %d\n",&storearr[i].code,&storearr[i].size,&storearr[i].workers,&storearr[i].total);
for (i=0;i<5;i++)
printf ("%-15d %-15d %-15d %-15d\n",storearr[i].code,storearr[i].size,storearr[i].workers,storearr[i].total);
fclose (filein);
return 0;
}