首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

什么叫syntax error : '&'解决方法

2012-03-31 
什么叫syntax error : &#includestdio.h#includestdlib.h#includestring.htypedef struct tnode /

什么叫syntax error : '&'
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct tnode /*该结构体类型为树结点的类型*/
{
char data;
struct tnode *lchild;
struct tnode *rchild;
} *bt;
void in_post_to_bt(char *in,char *post,int len,bt &T) /*由长度为len的中序序列in和后序序列post唯一确定一棵二叉树T*/
{
int k;
if(len<=0)
{
T=NULL;
return;
}

  for(char *temp=in;temp<in+len;temp++) /*在中序序列in中找到根节点所在的位置*/
if(*(post+len-1)==*temp)
{
k=temp-in; /*k为根结点在中序序列中的下标*/
T=(bt)malloc(sizeof(struct tnode));
T->data =*temp;
break;
}
in_post_to_bt(in,post,k,T->lchild ); /*建立左子树*/
in_post_to_bt(in+k+1,post+k,len-k-1,T->rchild ); /*建立右子树*/
}
void pre_visit(bt T) /*前序遍历树*/
{
if(T)
{
pre_visit(T->lchild);
pre_visit(T->rchild);
printf("%c",T->data);
}
}
int main()
{
char in[20],post[20];
int len_in,len_post,i,j;
  bt T;
while(in[i-1]!=' ')
{
scanf("%c",&in[i++]);
}
i=i-2;
while(post[j-1]!='\n')
{
scanf("%c",&post[j++]);
}
j=j-2;
len_in=i,len_post=j;
in_post_to_bt(in,post,len_in,T);
pre_visit(T);
return 0;
}
编译不通过,显示的错误是
  error C2143: syntax error : missing ')' before '&'
  error C2143: syntax error : missing '{' before '&'
  error C2059: syntax error : '&'
  error C2059: syntax error : ')'
都在红色的那一行,但是不知道为什么啊,求解啊


[解决办法]
不知道楼主用的什么编译器 我在VS2010上面运行的时候只有警告说i j局部变量没有初始化 后来我初始化之后 输入了a b c按回车就完了 不知道你是要实现什么功能~~~
[解决办法]
文件后缀从.c改为.cpp再试试。
[解决办法]

探讨
文件后缀从.c改为.cpp再试试。

[解决办法]
用C++编译器编译,应该没有语法错误。
用C编译器,应该有语法错误。

因为,C中没有应用,而C++中有。
[解决办法]
void in_post_to_bt(char *in,char *post,int len,bt *T) /*由长度为len的中序序列in和后序序列post唯一确定一棵二叉树T*/
{
int k;
if(len<=0)
{
*T=NULL;
return;
}

修改了两个地方,参数&T修改为*T, 语句T= NULL;修改为:*T = NULL;
在C语言中编译会出现这样的错误,&T这是属于引用吧,在C中没有引用。那就传地址吧。

热点排行