I'm trying to implement a list interface in C. It is a sorted list with items declared as
Code:
typedef struct {
char* str;
int len;
} Item;
I think the problem is in this function. I can create the list from a data file containing strings and then print it out using another function. However, when printing the list it prints out the same string twice. I will attach all relevant files.
Code:
void FindLocation(List* L, ListNode** Prev, Item item)
{
ListNode* Iterator;
Item anItem;
Iterator = L->head;
*Prev = NULL;
while( Iterator)
{
*Prev = Iterator;
if(strcmp(item.str, Iterator->data.str) > 0 )
{
fprintf(stdout, "The new item is greater than the iterator with data\n%s\n", Iterator->data.str);
break;
}
Iterator = Iterator->next;
}
}
The output never contains the debug string in the if block in the above function.
Here is a sample output:
Code:
t3\LinkSort\Debug>LinkSort input.data
Previous node is null.
New node has data This is line one.
.
Head node has data This is line one.
.
Previous node has data THis is line two..
New node has data THis is line two..
THis is line two.
THis is line two.