新手求助,关于链表问题

silenceRR 2012-03-07 09:00:47
#include<string.h>
#include<ctype.h>
#include<malloc.h>
#include<limits.h>
#include<stdio.h>
#include<stdlib.h>
#include<io.h>
#include<math.h>
#include<process.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1

typedef int Status;
typedef int Boolean;

typedef int ElemType;
#include <stdio.h>
#include <stdlib.h>
struct LNode
{
ElemType data;
LNode *next;
};
typedef LNode *LinkList;

void CreateList_L(LinkList &L,int n){
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
for(int i=n;i>0;--i){

p=(LinkList)malloc(sizeof(LNode));
scanf(&p->data);
p->next=L->next;L->next=p;
}
}

int main()
{
LinkList L;
CreateList_L(L,2);
m=L->next;
while(m)
{
printf("%d\n",p->data);
p=p->next;
}
}



VC6.0中报错:--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
C:\Documents and Settings\Administrator\桌面\1.cpp(34) : error C2065: 'p' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\1.cpp(34) : error C2440: '=' : cannot convert from 'struct LNode *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\1.cpp(35) : error C2227: left of '->data' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\1.cpp(36) : error C2227: left of '->next' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\1.cpp(36) : error C2440: '=' : cannot convert from 'int' to 'struct LNode *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\1.cpp(44) : error C2065: 'm' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\1.cpp(44) : error C2440: '=' : cannot convert from 'struct LNode *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\1.cpp(47) : error C2227: left of '->data' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\1.cpp(48) : error C2227: left of '->next' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\1.cpp(50) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.

1.obj - 1 error(s), 0 warning(s)


请问怎么解决???
...全文
92 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
面包大师 2012-03-07
  • 打赏
  • 举报
回复
(35) : error C2227: left of '->data' must point to class/struct/union
(36) : error C2227: left of '->next' must point to class/struct/union

改了未定义这个错误之后,相应的上边的错误也会没有了
面包大师 2012-03-07
  • 打赏
  • 举报
回复
(44) : error C2065: 'm' : undeclared identifier
类似的第44行中m未定义
面包大师 2012-03-07
  • 打赏
  • 举报
回复
(34) : error C2065: 'p' : undeclared identifier
以上错误表示,第34行中p未定义
pengchy 2012-03-07
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <malloc.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <math.h>
#include <process.h>

#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1

typedef int Status;
typedef int Boolean;
typedef int ElemType;

struct LNode
{
ElemType data;
LNode *next;
};
typedef LNode *LinkList;

void CreateList_L(LinkList &L,int n){
LinkList p = NULL;
L = (LinkList)malloc(sizeof(LNode));
L->next = NULL;
for(int i=n;i>0;--i){
p = (LinkList)malloc(sizeof(LNode));
scanf(&p->data);
p->next = L->next;
L->next = p;
}
}

int main()
{
LinkList L = NULL, m = NULL;
CreateList_L( L, 2 );
m = L->next;
while( m != NULL )
{
printf( "%d\n", p->data );
p=p->next;
}

return 0;
}
pengchy 2012-03-07
  • 打赏
  • 举报
回复
临时变量没有定义,定义上不就OK啦

69,371

社区成员

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

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