表达式语法错误 [英] error in expression syntax

查看:142
本文介绍了表达式语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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













#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);
}

推荐答案

display(front)

中,您尚未声明,因此编译器假定它是int.然后,您不能期望它充当->左侧的指针.您需要用

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

display(struct node *front)

替换该行,然后您的printf()调用中的任何一个将编译.

彼得

Then either of your printf() calls will compile.

Peter


这篇关于表达式语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆