#include<stdio.h>
#include<stdlib.h>
void print();
void insert(int);
struct node
{
int data;
struct node* next;
};
struct node* head;
void insert(int x)
{
struct node* temp=(node*)malloc(sizeof(node));
temp->data=x;
temp->next=head;
head=temp;
}
void print(void)
{
struct node* temp=head;
printf("the linked list is:\n");
while(temp!=NULL)
{
printf("%d ",temp->data);
temp=temp->next;
}
printf("\n");
}
main()
{
head=NULL;
printf("how many numbers?\n");
int n,x,i;
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter the number:\n");
scanf("%d",&x);
insert(x);
print();
}
return 0;
}
comiling error says "node undeclared" first use in program,although i made "node" a global one this code is just for creating a linked list and adding user input values into the front of the linked list insert(int x) function does the insertion work.
node, onlyhead- Ingo Leonhardtstruct node* temp=(node*)malloc(sizeof(node));-->struct node* temp=malloc(sizeof(struct node));- LPsfreeing themallocated memory before the end of program.. - LPsmain()function. (regardless of the poorly written microsoft C compiler allowing such errors) those two signatures are:int main( void )andint main( int, char** )Strongly suggest using the appropriate signature - user3629249