I have some problem with linked list FIFO(first in first out).
This is my code:
typedef int datatype;
typedef struct node *nodep;
struct node *first,*last,*p;
struct node
{
datatype data;
nodep *next;
};
void create();
void list();
void create()
{ char *tl;
do
{
p=(struct node*)calloc(5,sizeof(struct node));
p->data=random(100);
p->next=NULL;
if(first==NULL) first=p;
else last->next=p;
last=p;
printf("do you still want to create?(y/n):");scanf("%s",&tl);
getch();
}while(*tl!='n');
}
void list()
{
while(p!=NULL)
{
printf("%3d",p->data);
p=p->next;
}
getch();
}
main()
{
first=NULL;
create();
list();
getch();
}
But my program doesn't run. Can you help me to slove this problem?