Hi. I have a troubble with reading string from file and saving it in a structure.
Here's my code:
FILE*t;
t=fopen("file.txt", "r");
wt=(pointer)malloc(sizeof(list));
w=wt;
for(i=0; i<3; ++i)
{
w=(pointer)malloc(sizeof(list));
fscanf(t, "%d", &w->id_t);
fscanf(t, "%s", &w->name);
fscanf(t, "%f", &w->price);
fscanf(t, "%d", &w->tax);
printf("%d\n", w->name); //for check
w->next=NULL;
fscanf(t, "%c", &c);
w=w->next;
}
The only problem is with
fscanf(t, "%s", &w->name);
What have I to do?