I'm learning liked lists in C too, I see you got it how linked lists work so here is how I would go about solving that problem, I used 3 pointers because that is how I'm used to code linked lists in C.
Hope that helps.
Code:
/*
* File: liked.c
* -------------
* Creates a linked list and prints the strings
* entered by the user.
*/
#include <stdlib.h>
#include <stdio.h>
typedef struct node{
char word[10];
struct node *next;
}NODE;
int main(void)
{
NODE *head = NULL;
NODE *prev,*curr;
char str[10];
printf("[ENTER TO QUIT] String: ");
while( gets(str) != NULL && str[0] != '\0' )
{
curr = (NODE*) malloc(sizeof(NODE));
//if head == NULL so it is the first position
if ( head == NULL )
head = curr;
else
//prev->next = current position
prev->next = curr;
//set the curr pointer to be the end
//of the linked list
curr->next = NULL;
prev = curr;
strcpy(curr->word,str);
printf("String: ");
}
curr = head;
// there is a null at the end of the linked list
// so we can do while != NULL
while ( curr != NULL )
{
printf("%s\n",curr->word);
// set the current position to be the next position
curr = curr->next;
}
return 0;
}