struct node {
int data;
struct node *next;
};
struct node * list,root;
list=NULL;
root=NULL;
Above is what I am trying to create in my program and my program when I compile gives error
kbc.c:8: warning: data definition has no type or storage class
kbc.c:8: error: conflicting types for ‘list’
kbc.c:7: note: previous declaration of ‘list’ was here
kbc.c:8: warning: initialization makes integer from pointer without a cast
kbc.c:9: warning: data definition has no type or storage class
kbc.c:9: error: conflicting types for ‘root’
kbc.c:7: note: previous declaration of ‘root’ was here
kbc.c:9: warning: initialization makes integer from pointer without a cast
Here is the full program if some one wants to see I am just making a program to write a link list
#include<stdio.h>
#include<stdlib.h>
struct node {
int data;
struct node *next;
};
struct node * list,root;
list=NULL;
root=NULL;
struct node * create_node(int );
int main ()
{
int i,j,choice;
printf("Enter a number this will be root of tree\n");
scanf("%d",&i);
printf("Give us choice 1 to enter more numbers 0 to quit\n");
scanf("%d",&choice);
switch (choice)
{
case 1:break;
case 2:break;
}
}
// end of function main
struct node * create_node(int data)
{
struct node *temp;
t emp = (struct node *)malloc(sizeof(struct node));
return temp;
}
rootis not a pointer. You may wantstruct node *list, *root;struct node *list,*root;still same error.listandrootare "global" variables, they will automatically be initialized to0(NULL) if you writestruct node *list, *root;.