变量未定义?明明定义了啊~

flyendlessly 2009-04-26 09:48:52
请教大家一个低级问题~
我在c函数中定义了一个int i作为循环变量,但编译通不过,说是未声明变量;
如果放在外面定义为全局变量的话,就能行了~
很疑惑
函数如下,动态建立单链表:
typedef struct Lnode
{
ElemType data;//ElemType 已定义为 int
struct Lnode *next;
}Lnode;

Lnode *create(ElemType a[],int length)
{
Lnode *head=(Lnode*)malloc(sizeof(Lnode)),*p;
head->next=NULL;
int i; //error C2143: syntax error : missing ';' before 'type'
printf("l=%d\n",length);
for(i=length-1;i>=0;i--) //error C2065:'i' : undeclared identifier
{
p=(Lnode*)malloc(sizeof(Lnode));
p->data=a[i];
p->next=head->next;
head->next=p;
}
return head;
}
非常困惑~
...全文
134 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
really3353 2009-04-26
  • 打赏
  • 举报
回复
LZ,你这个程序没有问题,你选择Clean,然后Rebuild all,可能就没问题了。呵呵
tlw112 2009-04-26
  • 打赏
  • 举报
回复

typedef struct Lnode
{
ElemType data;//ElemType 已定义为 int
struct Lnode *next;
}Lnode;

Lnode *create(ElemType a[],int length)
{
Lnode *head=(Lnode*)malloc(sizeof(Lnode)),*p; /** 是这里有问题吧 -- *p ? **/
head->next=NULL;
int i; //error C2143: syntax error : missing ';' before 'type'
printf("l=%d\n",length);
for(i=length-1;i>=0;i--) //error C2065:'i' : undeclared identifier
{
p=(Lnode*)malloc(sizeof(Lnode));
p->data=a[i];
p->next=head->next;
head->next=p;
}
return head;
}

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧