主题:运行时,这个循环终止不了.
#include<stdio.h>
#include<string.h>
struct student
{
int number;//学号
char name[20];//姓名
int age;//年龄
struct student* next;
};
struct student* greatlist();
struct student* showlist (struct student* head);
void main(void)
{
student* head = NULL;
head = greatlist();
showlist(head);
return;
}
struct student* greatlist()
{
student* head = NULL;
student* tail = NULL;
student* s = NULL;
while(1)
{
int Number;
int Aage;
char nName[20];
printf("请输入学号:");
scanf("%d",&Number);
printf("姓名:");
scanf("%d",nName);
fflush(stdin);
printf("年龄:");
scanf("%s",&Aage);
if(Number<=0)
{
break;
}
s = new student;
// s->name=nName;
strcpy(s->name,nName);
s->age = Aage;
s->number = Number;
s->next = NULL;
if(head == NULL)
{
head = tail = s;
}
else
{
tail->next = s;
tail = s;
}
}
return head;
}
struct student* showlist (struct student* head)
{
student* s1 = head;
while(s1 != NULL)
{
printf("姓名 年龄");
printf("%s%d",s1->name,s1->name);
s1 = s1->next;
}
printf("NULL\n");
return head;
}
#include<string.h>
struct student
{
int number;//学号
char name[20];//姓名
int age;//年龄
struct student* next;
};
struct student* greatlist();
struct student* showlist (struct student* head);
void main(void)
{
student* head = NULL;
head = greatlist();
showlist(head);
return;
}
struct student* greatlist()
{
student* head = NULL;
student* tail = NULL;
student* s = NULL;
while(1)
{
int Number;
int Aage;
char nName[20];
printf("请输入学号:");
scanf("%d",&Number);
printf("姓名:");
scanf("%d",nName);
fflush(stdin);
printf("年龄:");
scanf("%s",&Aage);
if(Number<=0)
{
break;
}
s = new student;
// s->name=nName;
strcpy(s->name,nName);
s->age = Aage;
s->number = Number;
s->next = NULL;
if(head == NULL)
{
head = tail = s;
}
else
{
tail->next = s;
tail = s;
}
}
return head;
}
struct student* showlist (struct student* head)
{
student* s1 = head;
while(s1 != NULL)
{
printf("姓名 年龄");
printf("%s%d",s1->name,s1->name);
s1 = s1->next;
}
printf("NULL\n");
return head;
}