Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
I was clear the first error "ne = (temp *) malloc(sizeof(temp)); //error in expression syntax". correct syntax is: ne = (struct node *) malloc(sizeof(struct node));

2) i am trying 2nd error "<b>printf("%d\n",front->data); // error in pointer structure required on left side of -> or->*</b>" any one help me how to clear this error






C++
#include
#include

// creating structure
struct node
{
int data;
struct node *next;	// this variable is refering the struct node
}*front,*temp,*get,*ne;

int main()
{
front = NULL;
clrscr();
// insert the queue element
// insert function declaration
add(&front,56);
add(&front,88);
add(&front,44);
// display the queue element
display(front);

getch();
return 0;
}

//definition of the insert function
add(struct node *temp,int val)
{
ne = (temp *) malloc(sizeof(temp)); //error in expression syntax
//ne = (temp *) malloc(10*sizeof(temp)); //error in expression syntax
if(temp == NULL)
{
temp->data = val;
temp->next = NULL;

ne = temp;
}
else
//struct node *p;
{
get = front;
get->data = val;
get->next = ne;
}
}

display(front)
{
int count=0;
while(front != NULL)
{
printf("%d\n",front->data); // error in pointer structure required on left side of -> or->*
//printf("%d\n",(*front).data); // error in invalid inderiction
count++;
}
printf("No of Nodes: %d\n",count);
}
Posted
Updated 6-Oct-11 18:53pm
v3

1 solution

In
C
display(front)
you haven't declared a type for front, so the compiler assumes it is an int. You can't then expect it to behave as a pointer on the left side of ->. What you need is to replace that line with
C
display(struct node *front)
Then either of your printf() calls will compile.

Peter
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900