【发布时间】:2014-01-22 14:14:07
【问题描述】:
好的,这是我的问题哪种方式会更好,解释会很棒。回到我的代码,我在保存到文件时遇到问题,基本上我的函数为第一个客户保存项目,但不是为第二个客户保存项目。我做错了什么?如果我的其余代码是必要的,我可以发布它,但它就像 500 行。
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;
}
【问题讨论】:
-
嗯,没有错误,就像我说的它保存了客户列表,但没有保存第二个客户的内部列表
标签: c file linked-list