I have a text documet which has the following data
$
osobny automobil
Ferrari
Autobazar Pestovatelska 4 Bratislava
68957
2012
udrziavane cervene dvojdverove
$
kamion
Renault magnum
AUTO Modranska 5 Senec
28000
2016
po havarii opraveny v dobrom stave
$
karavan
Kostitras
JANA, Vitanova 147
20250
2010
Voz na dovolenku
The structure looks like this:
typedef struct auta {
char kategoria [50];
char znacka [50];
char predajca [100];
int cena;
int rok_vyroby;
char stav_vozidla [200];
struct auta *dalsi;
}AUTA;
And the thing my fucntion is supposed to do is read from this file a printf the number of entries. For example $ counts as one entry, so there would be three entries total. I have found it quite stupid to do this entry by entry with a different structure pointer as i am doing it now but the problem is i dont know how to make a sensible loop. What i have so far is how i read the first entry from the file.
AUTA *p=NULL;
p=(AUTA*)malloc(sizeof(AUTA));
fgets(z[0],5,fr);
fgets(p->kategoria,50,fr);
fgets(p->znacka,50,fr);
fgets(p->predajca,100,fr);
fscanf(fr,"%d",&p->cena);
fscanf(fr,"%d\n",&p->rok_vyroby);
fgets(p->stav_vozidla,200,fr);
So the question would be how to load entries from the text file into the structure using a loop.