So here's my problem I have inner structure inside of client. How can I know while reading from txt file that I'm reading item data or client data for my list?
struct item
{
char item_name[30];
char item_state[30];
float item_price;
char item_status[30];
float item_price_if_not;
struct item *next;
};
struct client
{
char client_name[30];
char client_last_name[30];
struct item *item_data;
struct client *next;
};
void savetxt(struct client *head)
{
FILE *f;
f = fopen("data.txt","w");
if(f == NULL)
{
printf("error");
}
struct item *CurrentItem = head->item_data;
while(head != NULL)
{
fprintf(f,"%s %s\n",head->client_name,head->client_last_name);
while(CurrentItem != NULL)
{
fprintf(f,"%s %s %f %s %f ",CurrentItem->item_name,CurrentItem->item_state,CurrentItem->item_price,CurrentItem->item_status,CurrentItem->item_price_if_not);
CurrentItem = CurrentItem->next;
}
head = head->next;
if(head != NULL)
{
CurrentItem = head->item_data;
}
fprintf(f,"\n\n");
}
fclose(f);
return NULL;
}