S
saurabh
#include<stdio.h>
#include<stdlib.h>
Hi gurus,
I am trying to compile the following code ,And I am getting an error on the
line labeled /*This one*/.
The error says,
"expected expression before 'node'"
Can someone please explain me the reason?
struct node
{
int data;
struct node* next;
};
typedef struct node node;
node * make_n(node * nodeptr,int n)
{
int i=0;
node* newnode=NULL;
/*Please check the following line*/
nodeptr=(node*)malloc(sizeof node);/*This one*/
nodeptr->next=NULL;
nodeptr->data=1;
node * firstnode=nodeptr;
for(i=2;i<n+1;i++)
{
newnode=(node*)malloc(sizeof node);
newnode->data=(2*i);
newnode->next=NULL;
nodeptr->next=newnode;
nodeptr=newnode;
}
return firstnode;
}
#include<stdlib.h>
Hi gurus,
I am trying to compile the following code ,And I am getting an error on the
line labeled /*This one*/.
The error says,
"expected expression before 'node'"
Can someone please explain me the reason?
struct node
{
int data;
struct node* next;
};
typedef struct node node;
node * make_n(node * nodeptr,int n)
{
int i=0;
node* newnode=NULL;
/*Please check the following line*/
nodeptr=(node*)malloc(sizeof node);/*This one*/
nodeptr->next=NULL;
nodeptr->data=1;
node * firstnode=nodeptr;
for(i=2;i<n+1;i++)
{
newnode=(node*)malloc(sizeof node);
newnode->data=(2*i);
newnode->next=NULL;
nodeptr->next=newnode;
nodeptr=newnode;
}
return firstnode;
}