为什么gets函数无效了
为什么下面insert函数中的gets函数无效啊, 运行的时候像没有那个语句一样,直接进行下个语句了。我是菜鸟啊,学校的作业,谢谢大家了
#include"stdio.h"
#include"string.h"
typedef struct node
{
char name[20];
int num;
int math,eng,phy;
struct node *next;
}linklist,*list;
list insert(list L)
{
int x;
list p,r,b; r=L;
printf("please input the Number:");
scanf("%d",&x);
while(x!=-1){
p=(list)malloc(sizeof(linklist));
printf("please input the name:");
gets(p->name);
printf("please input the math:");
scanf("%d",&p->math);
printf("please input the eng:");
scanf("%d",&p->eng);
printf("please input the phy:");
scanf("%d",&p->phy);
p->num=x; r->next=p; r=r->next; r->next=NULL;
printf("please input the Number:");
scanf("%d",&x);
}
return(L);
}
list creatlist()
{ list L;
L=(list)malloc(sizeof(linklist));
L->num=-1;
L->next=NULL;
L=insert(L);
return(L);
}
list output(list L)
{
list r; r=L->next;
if(r==NULL) return L;
while(r!=NULL)
{ printf("the num is:%d\n",r->num);
printf("name:%s\n",r->name);
printf("math:%d\n",r->math);
printf("eng:%d\n",r->eng);
printf("phy:%d\n",r->phy);
printf("----------------------\n");
r=r->next; }
return L;
}
void main()
{ list L;
L=creatlist();
printf("done\n");
output(L);
getch();
}