Hi, I wrote this code and I don't seem to get why it gives me a runtime error...
Any help in the matter will be much apreciated.
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int info;
struct node * next;
}*listptr;
void print(listptr list)
{
listptr p;
p=list;
while (p)
{
printf("%d ",p->info);
p=p->next;
}
}
void push(struct node **s,int x)
{
struct node *q;
q=(struct node *)malloc(sizeof(struct node));
q->info=x;
q->next=*s;
*s=q;
}
void main()
{
int n;
listptr list;
scanf("%d",&n);
while (n!=999)
{
push(&list,n);
scanf("%d",&n);
}
print(list);
}