c - 'Node' undeclared (first use in this function) in DevC++ -


i have following code insert element in linkedlist. havebeen following tutorials , unable spot error in code.

i using devc++ , gives me compile time error says: [error] 'node' undeclared (first use in function)

 #include<stdio.h> #include<conio.h> #include<stdlib.h>  struct node{  int data;  struct node* next; }; struct node* head;  //global variable int main(){     head = null;  //empty list     int n, i, x;     printf("how many numbers enter");     scanf("%d", &n);     for(i=0; i<n; i++){         printf("enter number want add list:");         scanf("%d", &x);         insert(x);         print();     } }   void insert(int x){ node* temp= (node*)malloc(sizeof(struct node)); //i error here temp->data = x; //temp->next = null; //redundant //if(head!= null){ temp->next = head;  //temp.next point null when head null nd otherwise head pointing //} head = temp; }  void print(){     struct node* temp1 = head;  //we dont want tomodify head store in atemp. bariable , traverse     while(temp1 != null){          printf(" %d", temp1->data);          temp1= temp1->next;     }     printf("\n"); }  

create more modular link list library...your program less readable..moreover use typedef as possible when using structure in c..that give more rights use node* instead of struct node* every time...


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -