我想要在函数create中多次执行输出结构体指针的函数 input,来建立一个动态链表。第一次input函数运行正常,但是在第二次运行input时,第一个需要运行的gets()函数被跳过去了。不清楚这是为什么。
struct goods *create(int *pn)
{
struct goods *p1,*p2,*head;
int i=0;
p1=input();
p2=p1;
while(p1->num!=0){
i++;
if(i==1) head=p1;
else p2->next=p1;
p2=p1;
p1=input();
}
p2->next=NULL;
*pn=i;
return(head);
};
struct goods *input(void)
{
char assist[25];
struct goods *p;
p=(struct goods *)malloc(LEN);
printf("input the number of a sort of goods\n");
gets(assist); p->num=atol(assist);
printf("input the name of the sort of goods\n");
scanf("%[^\n]%*c",p->name);
printf("input the mod of the sort of goods\n");
gets(assist); p->mod=atoi(assist);
printf("input the price of the sort of goods\n");
gets(assist); p->price=atof(assist);
printf("input the producer of the sort of goods\n");
scanf("%s",p->producer);
return(p);
};