c - traversing through the linked list and returning the char* values -
i having problem returning char* values linked list can please please help how can homecoming char* values within while loop? when seek run programme single value linked list looping forever next code:
char * list_next(list *l) { list *currentposition = null; currentposition = l->next; //skipping dummy value in singly linked list while (currentposition != null) { currentposition = currentposition->next; homecoming currentposition->charvalue; } homecoming null; }
this how calling function:
char * item; while(item = list_next(list)) printf("%s ",item);
it easier
list* current = list->next; //skip dummy while(current) { printf("%s ", current->charvalue); current = current->next; }
but since have function , in format you've got you'd following:
char* list_next(list **l) { if (*l != null) { char* value = (*l)->charvalue; *l = (*l)->next; homecoming value; } homecoming null; }
and phone call so
list* temp_list = my_list->next; //skip dummy char * item; while(item = list_next(&temp_list)) printf("%s ",item);
you can homecoming 1 value function. create recurring calls function had in while loop move through entire list have modify input parameter next phone call in while loop operates on next element in list. notice **
in function parameters.
c
No comments:
Post a Comment