所以我想重新启动链表的循环以再次打印值,正如您在代码中看到的那样,如果我运行它,我只会有一次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("%dn",n_char);
fprintf(fout, "%d -> %sn", 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 - %sn", 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
}
}
您可以将给定的地址复制到虚拟指针中。使用该指针循环访问您的列表并在使用后将其丢弃!通常,除非有必要,否则更改参数中给出的值是一个坏主意:)