链表在输出的时候系统要求停止
#include <stdio.h>#include <stdlib.h>
#include <string.h>
struct S
{
char name[20];
int number;
struct S *next;
};
int main()
{
struct S *head=NULL;
struct S *current,*prev;
char input[20];
puts("Enter your name");
while(gets(input)!=NULL && input[0]!='\0')
{
current=(struct S *)malloc(sizeof(struct S));
if(head==NULL)
head=current;
else
prev->next=current;
strcpy(current->name,input);
puts("Enter your number");
scanf("%d",¤t->number);
while(getchar()!='\n')
continue;
puts("Enter next student");
prev=current;
}
if(head==NULL)
puts("no date");
else
puts("now output the contents");
current=head;
while(current!=NULL)
{
printf("name : %s number : %d\n",current->name,current->number);
current=current->next;
}
current=head;
while(current!=NULL)
{
free(current);
current=current->next;
}
return 0;
}
为什么在输出的时候系统要求停止呢 我有尝试把输出的语句删去就不会提示
我就想问下是什么原因
在用vc6.0