读书人

C编程调试出现有关问题

发布时间: 2012-03-21 13:33:15 作者: rapoo

C编程调试出现问题
#include <stdio.h>
#include <malloc.h>
struct stu
{int num;
struct stu * next;
};

void main()
{int len=1,i;
struct stu *p1,*p2,*head,* new1,*new1head;
p1=p2=head=(struct stu *) malloc(sizeof(struct stu));
printf( "input number(0:list end): ");
scanf( "%d ",&p1-> num);
while(p1-> num!=0)
{p1=(struct stu *)malloc(sizeof(struct stu));
printf( "input number(0:list end): ");
scanf( "%d ",&p1-> num);
if(p1-> num==0)
p2-> next=NULL;
else
{p2-> next=p1;
p2=p1;
len++;
}
}
p1=head;
printf( "\noriginal list:\n ");
do
{printf( "%4d ",p1-> num);
if(p1-> next!=NULL)
p1=p1-> next;
}while(p1-> next!=NULL);
printf( "%4d ",p1-> num);

for(i=0;i <len;i++)
{p2=p1=head;
while(p1-> next!=NULL)
{p2=p1;
p1=p1-> next;
}
if(i==0)
new1head=new1=p1;
else
new1=new1-> next=p1;
p2-> next=NULL;
}
printf( "\n\nnew list:\n ");
p1=new1head;
for(i=0;i <len;i++)
{printf( "%4d ",p1-> num);
p1=p1-> next;
}
printf( "\n ")
}

出错提示:E:\C语言上机调试\1112.cpp(54) : error C2143: syntax error : missing '; ' before '} '
Error executing cl.exe.

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



[解决办法]
最后的printf( "\n ")后面加上分号

读书人网 >C++

热点推荐