i have looked at both codes. but unfortunately its a little bit too complicated for a beginner like me
i was wondering is there any possibility with my current code at hand that there is a simple code solution
So that instead of my code showing this:
Varunummer: Namn Lagersaldo
————————————————————————————————————————————— —————
0 0
0 0
0 0
0 0
0 0
0 0
it will show this instead:
Varunummer: Namn Lagersaldo
————————————————————————————————————————————— —————
123 majs 12
234 banan 45
432 klossar 32
654 klas 32
435 soppa 32
121 granat 23
Code:
void readFromFile(char file[], int *antal_varor, struct storagemanipulation *inventory)
{
int i;
printf("Enter the name of the file that you would like to open: \n");
scanf("%s", file);
char namn[30];
int lagersaldo, varunummer;
FILE *fp;
fp=fopen(file,"r");
if (fp!=NULL)
{
fscanf(fp, "%d\n", antal_varor);
for (int i = 0; i < *antal_varor; i++)
{
if(fscanf(fp, file, "%s %d %d", inventory[i].namn, &inventory[i].lagersaldo, &inventory[i].varunummer) == 3)
{
inventory[i].varunummer = varunummer;
strcpy(inventory[i].namn, namn);
inventory[i].lagersaldo = lagersaldo;
}
}
}
else
{
printf("no access to the File\n");
}
fclose(fp);
}