#include <stdio.h>
struct node {
struct node *next,*prev;
int data;
} n,*start;
void add_element (int e);
static int j=0;
int main ()
{
int i,element,l,choice;
choice=1;
struct node *temp;
start = NULL;
while (choice == 1)
{
printf("What do you want 0 exit 1 to add\n");
scanf("%d",&choice);
if(choice==0)
break;
printf("Enter data to be entered\n");
scanf("%d",&element);
add_element(element);
}
}
void add_element(int e)
{
printf("\n printing from function %d\n",e);
struct node *temp;
if(j==0)
{
start = (struct node *) malloc (sizeof(struct node)) ;
start->next=NULL;
start->data=e;
printf("the data entered is %d \n",start->data);
}
j++;
}
When ever I am compiling the above code
the error I am getting
In function
add_element is
linklist.c: In function ‘add_element’: linklist.c:34: warning: incompatible implicit declaration of built-in function ‘malloc’am I doing any mistake by declaring malloc as below?
start = (struct node *) malloc (sizeof(struct node)) ;


Sign In
Create Account


Back to top









