X-Git-Url: http://git.harvie.cz/?p=svn%2FCll1h%2F.git;a=blobdiff_plain;f=demos%2Fansi-c%2Ffloat-list-plain-c.c;fp=demos%2Fansi-c%2Ffloat-list-plain-c.c;h=0501873547280de9143f0f9e644b9556a5044f53;hp=0000000000000000000000000000000000000000;hb=ea514b9e6351878fef9638813f50ce7013e8a832;hpb=eac5d6c70c3babc9056f059edd88a2c1a82bc7e9 diff --git a/demos/ansi-c/float-list-plain-c.c b/demos/ansi-c/float-list-plain-c.c new file mode 100644 index 0000000..0501873 --- /dev/null +++ b/demos/ansi-c/float-list-plain-c.c @@ -0,0 +1,60 @@ +#include +#include + + +struct Node +{ + float f; + struct Node* next; +}; + +void IterateList (struct Node* HeadList); +struct Node* makelist(struct Node** Head, struct Node** Tail); + +struct Node* makelist(struct Node** Head, struct Node** Tail) +{ + struct Node* new = (struct Node *)malloc(sizeof (struct Node)); + new->next = NULL; + + if (*Head == NULL) + { + *Head = new; + *Tail = *Head; + } + else + { + (*Tail)->next = new; + *Tail = new; + } + return (new); +} +void IterateList (struct Node* HeadList) +{ + struct Node* current = HeadList; + + while (current != NULL) + { + printf("The float you entered is %f\n",current->f); + current = current->next; + } +} +int main(void) +{ + struct Node* head = NULL; + struct Node* tail = NULL; + struct Node* curr = NULL; + int i; + + for(i=0; i < 20; i++) + { + /* create node */ + curr = makelist(&head,&tail); + printf("Enter float :\n"); + scanf("%f", &(curr->f)); + } + + /* now iterate the list */ + IterateList(head); + + return 0; +}