You've got a number of issues.
1) Unlike Java, main always returns an int in C and C++. Always.
2) You have 'name' defined as a char. Just one. Not a string of them, only one single character.
3) You don't have a 'break;' in your switch's case statement. While this isn't 'wrong' per say, it probably won't be what you want it to be once you have more than one case.
4) Consider reading the FAQ entry on getting input from a user for better methods of input.
5) When you get 'name' fixed, you'll need to look into the string functions such as strcpy to copy it over correctly from place to place.
6) Linked lists are really easy, especially when all you want to do is prepend to one. (Though I prefer doubly linked lists, because they're actually easier to work with.)
Code:
void prepend( struct Node **mylist, struct Node *thisnode )
{
thisnode->next = *mylist;
*mylist = thisnode;
}
You call this function with something like this:
Code:
struct Node *thelist;
struct Node *somenode;
...set 'thelist' to NULL, or put something in it, either way...
...allocate and fill up 'somenode'...
prepend( &thelist, somenode );
Since it sounds like that's what you want. First in, last out. What we're doing is passing a pointer to the actual list so that we can update what it points to inside the function. Otherwise, if we didn't use a pointer to it, the change wouldn't take place unless you did it this way:
Code:
thelist = prepend( thelist, somenode );
And the prepend function would have to look like this:
Code:
struct Node *prepend( struct Node *thelist, struct Node *thisnode )
{
thisnode->next = thelist;
return thisnode;
}
Here you just make the new node point to the top of the list, and return it. It's return would have to be assigned to the origional list pointer, otherwise the update wouldn't happen, and you'd end up with a ton of nodes all pointing to the same place, each of them thinking they're the top.
Quzah.