visual c++ 里面出现的错误 error C2601:local function definitions are illegal
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct node
{
int Elem;
struct node *next;
}LNode, *Linklist;
Linklist createlist(int n)
{
Linklist p,r,list=NULL;
int i;
int e;
for(i=0;i<n;i++)
{
scanf("%d",&e);
getchar();
p=(Linklist)malloc(sizeof(LNode));
p->Elem=e;
p->next=NULL;
if(!list)
list=p;
else
{
r->next=p;
r=p;
}
return list;
}
void insertElem(Linklist *list, Linklist q,int e)
{
Linklist p;
p=(Linklist *)malloc(sizeof(LNode));
p->Elem=e;
if(!(*list))
{
*list=p;
p->next=NULL;
}
else
{
p->next=q->next;
q->next=p;
}
}
void delNode(Linklist *list, Linklist q)
{
Linklist r;
if(q=*list)
{
*list=q->next;
free(q);
}
else
{
for(r=*list;r>=q;r=r->next);
if(r->next!=NULL)
{
r->next=q->next;
free(q);
}
}
}
void destroyLinklist(Linklist *list)
{
Linklist p,q;
p=*list;
while(p)
{
q=p->next;
free(q);
p=q;
}
*list=NULL;
}
void main()
{
int e,i;
Linklist l,q;
q=l=createlist(1);
scanf("%d",&e);
while(e)
{
insertElem(&l,q,e);
q=q->next;
scanf("%d",&e);
}
q=l;
printf("The content of the linklist\n");
while(q)
{
printf("%d ",q->data);
q=q->next;
}
q=l;
printf("\nDelete the fifth element\n");
for(i=0;i<4;i++)
{
q=q->next;
}
delNode(&l,q);
q=l;
while(q)
{
printf("%d ",q->data);
q=q->next;
}
destroyLinklist(&l);
getchar();
}
代码编译后出现
E:\VC实验\链表\.cpp(35) : error C2601: 'insertElem' : local function definitions are illegal
E:\VC实验\链表\.cpp(52) : error C2601: 'delNode' : local function definitions are illegal
E:\VC实验\链表\.cpp(71) : error C2601: 'destroyLinklist' : local function definitions are illegal
E:\VC实验\链表\.cpp(84) : error C2601: 'main' : local function definitions are illegal
E:\VC实验\链表\.cpp(118) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
[解决办法]
低级错误?
函数写完后,}后面要加分号;
[解决办法]
createlist函数括号不配对。