This the error that I get. I'm trying to implement linked lists in c language.
prog.c: In function ‘Insert’: prog.c:33:26: error: ‘node’ undeclared (first use in this function) struct node* temp = (node*)malloc(sizeof(struct node));
the code is as below
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node* next;
};
struct node* head;
void Insert(int x);
void Print();
int main(void){
head = NULL;
printf("how many numbers?");
int n,i,x;
scanf("%d",&n);
for(i=0;i<n;i++){
printf("Enter the number");
sacnf("%d",&x);
Insert(x);
Print();
}
return 0;
}
void Insert(int x){
struct node* temp = (node*)malloc(sizeof(struct node));
temp->data = x;
(*temp).next = head;
head = temp;
}
void Print(){
struct node* temp = head;
printf("\nThe List is ");
while(temp!=NULL){
printf(" %d", temp->data);
temp=temp->next;
}
}