因此,我想重新启动链表的循环以再次打印值,如您在我的代码中看到的那样,如果我运行它,我将只有一次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
}
}
答案 0 :(得分:1)
您可以将给定的地址复制到虚拟指针中。使用该指针可以遍历您的列表,并在使用后将其丢弃!通常,除非必要,否则更改参数中给定值的想法很糟糕:)