Hey there,
I need help as i'm new in C.
I have a linked list that i'm posting here but i need to know if it's good first.
Secondly i want to know how to scan a group of words in one line and after pressing enter i want the words to be printed.
I guess this has to be in my main.. no idea how to do that
Hope i'm clear
Thanks for the helpCode:#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_WORDS typedef struct info { void *data; struct info *next; }INFO; /*---------------CREATING THE NODE-------------*/ INFO *list_create(void *data) { INFO *node; if (!(node=malloc(sizeof(INFO)))) return NULL; node->data=data; node->next=NULL; return node; } /*--------------INSERTING THE NODES-------------*/ INFO *list_insert(INFO *node, void *data) { INFO *new_node; new_node = list_create(data); new_node->next = node->next; node->next = new_node; return new_node; } /*-------------INSERT AT BEGINNING-------------*/ INFO *list_insert_beg(INFO *list, void *data) { INFO *new_node; new_node = list_create(data); new_node->next = list; return new_node; } /*-------------REMOVING THE NODE--------------*/ int list_remove(INFO *list, INFO *node) { while (list->next && list->next != node) list = list->next; if (list->next) { list->next = node->next; free(node); return 0; } else { return -1; } } /*------------------------OPERATION ON LIST------------------*/ /*----------TRAVERSING THE LIST----------------*/ int list_trav_each(INFO *node, int(*func)(void*)) { while (node) { if (func(node->data)!=0) return -1; node = node->next; } return 0; } /*-----------SEARCHING THE LIST------------*/ INFO *list_find(INFO *node, int(*func)(void*,void*), void *data) { while (node) { if(func(node->data, data)>0) return node; node=node->next; } return NULL; }



1Likes
LinkBack URL
About LinkBacks



