Well... '%s' will assume the argument is a string, or more closely a char*, since you're passing a Node* which is a container class, you can't expect printf() to knwo, what to do with it..
Why not make it wee bit more simple like:
Code:
printf("\n node /t %s", temp->string);
Since you know your Node struct has a member called string, which is a char*.
Byt the way what good is this ??
Code:
Node *addhead(char *string, Node *temp)
{
Node *new = newNode(string);
Node *head = NULL;
printf("\n node /t %s", temp);
head = new;
printf("\n List /t %s", new);
return (new);
}
Since you create the
new container, which is pointing to a copy of the Node struct which has (or should have) initialy set it's member
string to the value of argument
string yet it is practicaly doing nothing...
Then you assign a new Node* called
head with the same memory address.. yet when the function returnes it is only the
new member which is returned, which effectively will kill your
head container...
I'm suspecting you wanted something like:
Code:
Node *addhead(char *string, Node *temp)
{
Node *new = newNode(string);
temp->next = new;
new->next = NULL;
return (new);
}
For the printing of things I can't see what you're trying to do.. You create a form of linked list, yet only have a pointer to the next item, in order to print the entire list, you need to know teh initial list starting container, and have a dedicated printing function which would run through the list, given the starting point, printing whatever it encounters...
Perhaps something like:
Code:
int print_list(Node* start)
{
Node* tmp=start;
int i=0, j;
while(tmp){
printf("> %s\n", tmp->string);
for(j=0; j < i; ++j)
printf(" ");
tmp = tmp->next;
++i;
}
return i;
}
Not only will this print every
string container in your list, but it will also return how many items your list is holding.
But if you plan on doing some serius mengling with this, I would suggest somethign like a double linked list, so you can search forward or backwards through it, given teh required action.