Here I just given you program to understand linked list.
Code:
Basic linked list example
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Linkedlist {
char *str1;
struct Linkedlist *next1;
};
int main(void) {
char line[1024];
struct Linkedlist *h = NULL;
struct Linkedlist *n = NULL;
while(fgets(line, 1024, stdin) != NULL) {
n = (struct Linkedlist *)malloc(sizeof(struct Linkedlist));
n->next1 = h;
h = n;
n->str1 = strdup(line);
}
while(h != NULL) {
printf("%s\n", h->str1);
h = h->next1;
}
return 0;
}
Bookmarks