好吧,所以这里是我的问题我想弄清楚如何编写我的单链表到文件,不知道应该怎么用,所以我去了txt文件和fprintf不知道如果如果有人能够说出哪种方式会更好,解释会更好,那该多好。那么回到我的代码我有问题保存到文件基本上我的函数为第一个客户端保存项目,但不保存第二个项目。我做错了什么?如果我的代码的其余部分是必要的我可以发布它,但它像500行。保存到txt文件链接列表
struct item
{
char item_name[30];
char item_state[30];
double item_price;
char item_status[30];
double 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)
{
printf("try");
fprintf(f,"%s\n",head->client_name);
fprintf(f,"%s\n",head->client_last_name);
while(CurrentItem != NULL)
{
printf("tryitem");
fprintf(f,"%s\n",CurrentItem->item_name);
fprintf(f,"%s\n",CurrentItem->item_state);
fprintf(f,"%fp\n",CurrentItem->item_price);
fprintf(f,"%s\n",CurrentItem->item_status);
fprintf(f,"%fp\n",CurrentItem->item_price_if_not);
CurrentItem = CurrentItem->next;
}
head = head->next;
fprintf(f,"\n\n");
}
fclose(f);
return NULL;
}
错误?问题? –
那么没有错误,就像我说它保存客户端列表,但第二个客户端的内部列表没有保存 – user3209183