#include <stdio.h>
#include <stdlib.h>
typedef int DataType;
struct node
{
DataType info;
node * next;
};
int main(void)
{
struct node *top, *tep;
int d;
top = (struct node *)malloc(sizeof(struct node));
if (top == NULL)
{
printf("init error:\n");
return 0;
}
else
{
top->info = 0;
top->next = NULL ;
}
printf("enter a data:\n");
scanf("%d", &d);
while ( getchar() != 'q' )
{
tep = (node *)malloc(sizeof(node));
if (tep != NULL)
{tep->info = d;
tep->next = top;}
top = tep;
printf("enter a data:\n");
scanf("%d", &d);
}
printf("read finished \n");
while (top->next != NULL)
{
printf("the data is %d\n", top->info);
tep = top;
top = top->next;
free(tep);
}
//printf("the data is %d\n", top->info);
return 0;
}