i have little problem out here.
i must program singly linked list stuff, , hadn't got problems since now. stuck on deletion occurrence of substring given after function call in authors name in linked list.
the program snippet:
void list_delete_element(kniha_t* inode) { kniha_t *actualnode = inode; kniha_t *prevnode = null; kniha_t *tempnode = null; uchar_t needle[100]; uchar_t haystack[100]; ushort_t occur = 0; scanf("%s", &needle); lower_string(needle); while(actualnode != null) { copy_string(haystack, actualnode->autori); lower_string(haystack); if(search_string(haystack, needle)) { occur++; if ( null != prevnode) { prevnode->next = actualnode->next; } else { inode = actualnode->next; } tempnode = actualnode; actualnode = actualnode->next; free(tempnode); tempnode = null; } else { prevnode = actualnode; actualnode = actualnode->next; } } printf("deleted sa %hu nodes\n", occur); }
, stuff must load in it, ignoring ---:
http://pastebin.com/npver3y6
problem is, works ( :d )...until sweep occurrences.
example:
when type in pra, must delete nodes contains "pra". works charm...but when type "p", tells me, x occurrences freed, stay in buffer somewhere, because can print whole list out again!
thankful, can give me advice.
your list_delete_element
should take kniha_t**
can delete head node , prune linked list. current code, delete node, other functions doesn't know because inode
not changed.
you can update code
void list_delete_element(kniha_t* *inode) { kniha_t *actualnode = *inode; ... if ( null != prevnode) { prevnode->next = actualnode->next; } else { *inode = actualnode->next; } ... }
Comments
Post a Comment