这个程序为什么编译成功,无法运行
#include<stdio.h>#include<stdlib.h>
struct stu
{
int num;
char name[20];
int score;
struct stu *next;
};
int delete_node(struct stu *h,int x)
{
struct stu *p,*q;
q=h;p=h->next;
if(p!='\0')
{
while((p!='\0')&&(p->num!=x))
{
q=p;p=p->next;
}
if(p->num==x)
{
q->next=p->next;
free(p);
}
}
return 0;
}
int main(void)
{
int a,c,x;
char b[20];
struct stu *h,*s,*r,*n;
h=(struct stu *)malloc(sizeof(struct stu));
r=h;
scanf("%d",&a);
scanf("%s",b);
scanf("%d",&c);
while(c>=0)
{
s=(struct stu *)malloc(sizeof(struct stu));
s->num=a;
s->name[20]=b[20];
s->score=c;
r->next=s;
r=s;
scanf("%d",&a);
scanf("%s",b);
scanf("%d",&c);
}
scanf("%d",&x);
delete_node(s,x);
n=s->next;
while(n!='\0')
{
printf("%d\t%s\t%d\n",n->num,n->name,n->score);
n=n->next;
}
return 0;
}
[ 本帖最后由 xiaolou988 于 2013-4-23 22:13 编辑 ]