Hi, i'm having problems implementing a linked list . i want to create a list and then reverse the elements in a list, so for example i want to input Hello World. and the program output .dlroW olleH .here is my code so far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct linked_list {
char d;
struct linked_list *next;
} Element;
Element *insert(char h, Element **t){
Element *y = calloc( 1, sizeof(Element));
y->d = h;
y->next = *t;
*t = y;
return y;
}
int main(void)
{
Element *list = NULL;
char a;
printf("please type in sentence\n");
while((a = getchar()) != '.'){
list=insert (a, list);
}
for(; list ;list=list->next);
printf("%s\n", list);
}
apparently i am passing incopatible pointer types to function insert in the main function, however i cant see what i'm doing wrong. any help is greatly appreciated.



LinkBack URL
About LinkBacks


