0501873547280de9143f0f9e644b9556a5044f53
[svn/Cll1h/.git] / demos / ansi-c / float-list-plain-c.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4
5 struct Node
6 {
7 float f;
8 struct Node* next;
9 };
10
11 void IterateList (struct Node* HeadList);
12 struct Node* makelist(struct Node** Head, struct Node** Tail);
13
14 struct Node* makelist(struct Node** Head, struct Node** Tail)
15 {
16 struct Node* new = (struct Node *)malloc(sizeof (struct Node));
17 new->next = NULL;
18
19 if (*Head == NULL)
20 {
21 *Head = new;
22 *Tail = *Head;
23 }
24 else
25 {
26 (*Tail)->next = new;
27 *Tail = new;
28 }
29 return (new);
30 }
31 void IterateList (struct Node* HeadList)
32 {
33 struct Node* current = HeadList;
34
35 while (current != NULL)
36 {
37 printf("The float you entered is %f\n",current->f);
38 current = current->next;
39 }
40 }
41 int main(void)
42 {
43 struct Node* head = NULL;
44 struct Node* tail = NULL;
45 struct Node* curr = NULL;
46 int i;
47
48 for(i=0; i < 20; i++)
49 {
50 /* create node */
51 curr = makelist(&head,&tail);
52 printf("Enter float :\n");
53 scanf("%f", &(curr->f));
54 }
55
56 /* now iterate the list */
57 IterateList(head);
58
59 return 0;
60 }
This page took 0.288876 seconds and 3 git commands to generate.