帮你改了下~~#include<stdio.h>
#include<malloc.h>
int n = 0;
struct S
{
char name[20];
int num;
struct S *next;
}*head,*p1,*p2;
int main()
{
int i;
char ch;
head = (struct S*)malloc(sizeof(struct S));
p1 = head;
s: printf("Please Input your name:");
scanf("%s",&p1->name );
printf("Pleas Input your num:");
scanf("%d,",&p1->num);
while((ch = getchar())!='\n');
if(p1->num != 0)
{
n++;
p2 = (struct S*)malloc(sizeof(struct S));
p1->next = p2;
p1 = p2;
goto s;
}
else
{
p1->next =NULL;
}
printf("你一共输入了%d个名字!\n",n);
p1 = head;
i = 1;
while(p1->next != NULL)
{
printf("%d: name:%s num: %d\n",i,&p1->name,p1->num );
i++;
p1 = p1->next ;
}
/*
printf("输入学生名\n");
scanf("%s",&p1.c );//gets(p1.c); //这里成功输入“小明”,//输入过后程序就直接崩溃了,为什么?
printf("请输入数学成绩\n");
scanf("%d",&p1.a);
printf("请输入语文成绩\n");
scanf("%d",&p1.b);
printf("输入学生名\n");
scanf("%s",&p2.c );//gets(p2.c); //这里就直接跳过了,没让我输入。这是为什么?
printf("请输入数学成绩\n");
scanf("%d",&p2.a);
printf("请输入语文成绩\n");
scanf("%d",&p2.b);
head=&p1;
p1.next=&p2;
p2.next=NULL;
while(head!=NULL)
{
printf("%s %d %d\n",head->c,head->a,head->b);
head=head->next;
}*/
}
|