i have just tried to implement a simple linked list to store a name such as "ben", however it compiles but doesnt print out the values, here is my code:
Code:
#include <stdio.h>
typedef char DATA;
struct linked_list{
DATA d;
struct linked_list *next;
};
typedef struct linked_list ELEMENT;
typedef ELEMENT* LINK;
LINK string_to_list(char s[])
{
LINK head;
if( s[0]=='\0')
return NULL;
else{
head=malloc(sizeof(ELEMENT));
head->d=s[0];
head->next=string_to_list(s+1);
return head;
}
}
int main(void)
{
char *s;
LINK head=NULL;
LINK tail=NULL;
LINK next;
char a;
scanf("%s", string_to_list(&s));
for( ; head ; head = next ) {
printf( "%c", head->d );
next = head->next;
free( head );
}
return 0;
}
where have i gone wrong?