链表程序在vc中运行问题!!
程序代码:
#include <stdio.h> #include <stdlib.h> typedef struct Node { int DATA;//shujvyu struct Node *pNext; }NODE,* PNODE ;//NODE等价于 structural Node;PNODE等价于struct node* int main(void) { PNODE create_list(void); void traverse_list(pHead); PNODE pHead=NULL;//等价于struct Node *pHead=NULL pHead=create_list(); traverse_list(pHead); return 0; } PNODE create_list(void) { int len,i; int val; PNODE pHead1=(PNODE)malloc(sizeof(NODE)); if (NULL==pHead1) {printf("fenpeishibai ,chengxvzhongzhi!"); exit(-1); } PNODE pTail=pHead1; pTail->pNext=NULL; printf("qingshurujiedianshu :len ="); scanf("%d",&len); for (i=0;i<len;i++) { printf("qingshuru di %d jiedian shujv :",i+1); scanf("%d",&val); PNODE pNew=(PNODE)malloc(sizeof(NODE)); if (NULL==pNew) { printf("fenpeishibai ,chengxvzhongzhi!"); exit(-1); } pNew->DATA=val; pTail->pNext=pNew; pNew->pNext=NULL; pTail=pNew; } return pHead1; } void traverse_list(PNODE pHead) { PNODE p= pHead->pNext; while(NULL!=p) { printf("%d",p->DATA); p=p->pNext; } printf("\n"); }
vc显示错误为:
程序代码:
D:\vc\MSDev98\MyProjects\链表\链表.c(34) : error C2275: 'PNODE' : illegal use of this type as an expression D:\vc\MSDev98\MyProjects\链表\链表.c(8) : see declaration of 'PNODE' D:\vc\MSDev98\MyProjects\链表\链表.c(34) : error C2146: syntax error : missing ';' before identifier 'pTail' D:\vc\MSDev98\MyProjects\链表\链表.c(34) : error C2065: 'pTail' : undeclared identifier D:\vc\MSDev98\MyProjects\链表\链表.c(34) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct Node *' D:\vc\MSDev98\MyProjects\链表\链表.c(35) : error C2223: left of '->pNext' must point to struct/union D:\vc\MSDev98\MyProjects\链表\链表.c(45) : error C2275: 'PNODE' : illegal use of this type as an expression D:\vc\MSDev98\MyProjects\链表\链表.c(8) : see declaration of 'PNODE' D:\vc\MSDev98\MyProjects\链表\链表.c(45) : error C2146: syntax error : missing ';' before identifier 'pNew' D:\vc\MSDev98\MyProjects\链表\链表.c(45) : error C2065: 'pNew' : undeclared identifier D:\vc\MSDev98\MyProjects\链表\链表.c(45) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct Node *' D:\vc\MSDev98\MyProjects\链表\链表.c(46) : warning C4047: '==' : 'void *' differs in levels of indirection from 'int ' D:\vc\MSDev98\MyProjects\链表\链表.c(52) : error C2223: left of '->DATA' must point to struct/union D:\vc\MSDev98\MyProjects\链表\链表.c(54) : error C2223: left of '->pNext' must point to struct/union D:\vc\MSDev98\MyProjects\链表\链表.c(55) : error C2223: left of '->pNext' must point to struct/union 执行 cl.exe 时出错. 链表.obj - 1 error(s), 0 warning(s)
怎么回事?