Here, this compiles without error (I leave it up to you to discover any run-time anomalies):
Code:
#include <stdio.h>
struct node
{
char value;
struct node *next;
};
struct node *head=NULL, *tail=NULL;
void addNode(char);
void printList();
int main( void )
{
char input;
printf("Enter you name:\n");
input = getchar();
while( input != '\n' )
{
addNode( input );
input = getchar();
}
printf("\nYou have entered: ");
printList();
printf("\n\nProgram complete\n");
}
void addNode( char val )
{
struct node *insert;
insert = (struct node *) malloc( sizeof(struct node) );
insert->value = val;
insert->next = NULL;
if( head == NULL ) //if the list is empty
head = tail = insert;
else
{
tail->next = insert;
tail = insert;
}
}
void printList()
{
struct node *p = head;
while( p != NULL )
{
printf("%c", p->value );
p = p->next;
}
}