【发布时间】:2020-04-22 22:56:19
【问题描述】:
所以我想重新启动链表的循环以再次打印值,正如您在我的代码中看到的那样,如果我运行它,我只会有一次printf,因为它到达了列表的末尾,当第二个循环尝试转到列表时,指针已经在末尾,如何让它再次转到列表的开头?
void UC_show(L_uc_data *list, L_af_data *list1, FILE *fout)
{
//int number_char=0;
while (list) { // here its starts the loop of the principal list
//Get length from names
int n_char=strlen(list->uc_data.uc_name);
printf("%d\n",n_char);
fprintf(fout, "%d -> %s\n", list->uc_data.uc_number, list->uc_data.uc_name);
while (list1) { // here it starts a loop of the secondary list
fprintf(fout, "%d - %d - %d - %d - %d - %s\n", list1->number_uc, list1->start, list1->end, list1->done, list1->n_sessions, list1->af_name);
list1 = list1->next;
}
list = list->next; // it goes to the next entry of the principal list the loop of the second list should start from the beginning
}
}
【问题讨论】:
-
您只需将原始值保存在某处。
-
将原始引用存储在临时变量中。
L_uc_data *temp = list然后使用它恢复您的列表。理想情况下,应该通过临时指针进行迭代并保持初始指针不变,但是是的,你可以做其他方式。 -
您介意添加
main以便我们进行测试吗? -
已经使用@stanle 输入解决了问题,您需要的不仅仅是主要的测试,您需要所有的结构
标签: c function loops data-structures linked-list