I have a problem with an exercise. I should read the written file, which contains two struct one another, the second struct that is the product should stop reading when reading the # character from the file, and then start reading before the struct and then stock the product. Can you help me?
I can not read from the struct file, and then make it stop to the character #. I think I need two while where the first law the elements of struct magazine, and the second law of those struct product and stop at the character #.
Is there anyone who could write code like this?
The file with each item on a separate line, only the line of the struct product is on the same line:
(Cod_p name quantity)
the whole is only separated to a space.
the file is organized as follows:
ENG0002
high street,8
London
England
SCG8888 Shorts 200
FFSF888 shirt 200
#
TRA456456
Park road,88
London
England
ASDASD000 shorts 100
ADWC000 shirt 1000
YUAYO shoes 122
#
#include <stdio.h>
#include <stdlib.h>
struct magazine {
    char cod_m[30];
    char adress[30];
    char city[30];
    char nation[30];
    struct product* p;
    struct magazine* next;
    ``
};
struct product {
    char cod_p[10];
    char name[20];
    int quantity;
    struct product* next;
};
void read_st(struct magazzino* m);
int main() {
    struct magazzino* mag;
    read_st(mag);
}
void read_st(struct magazzino* m) {
    FILE* fp;
    fp = fopen("magazzino.txt", "r");
    while (!feof(fp)) {
        struct magazzino* m = (struct magazzino*)malloc(sizeof(struct magazzino));
        fscanf(fp, "%s\n%s\n%s\n%s\n", &m->cod_m, &m->adress, &m->city, &m->nation);
        m->next;
        printf("%s\n%s\n%s\n%s\n", &m->cod_m, &m->adress, &m->city, &m->nation);
    }
}
struct prodotto* LeggiProdotto(char filename) {
    FILE* fp = fopen("magazzino.txt", "r");
    while (!feof(fp)) {
        struct prodotto* p = (struct prodotto*)malloc(sizeof(struct prodotto));
    }
}
