#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define NAMESIZE 10
struct person_st
{
int id;
char name[NAMESIZE];
int age;
struct person_st *link;
};
struct person_st * create()
{
int str,i;
struct person_st *head,*current,*next;
head = (struct person_st *) malloc (sizeof(struct person_st));
printf("您需要添加几个学生?");
scanf("%d",&str);
current=head;
for(i=0;i<str;i++)
{
next = (struct person_st *) malloc (sizeof(struct person_st));
current->link = next;
current = next;
printf("请输入您的学号(01001):姓名:年龄【空格隔开】:");
scanf("%d%s%d",&next->id,next->name,&next->age);
}
next->link=NULL;
return head;
}
int main()
{
struct person_st *p;
p = create();
while(1)
{
printf("%d %s %d",p->id,p->name,p->age);
if(p->link != NULL)
{
p = p->link;
}
else
{
break;
}
}
return 0;
}
运行出现乱码,请教各位 , 程序那里有问题
#include <malloc.h>
#include <string.h>
#define NAMESIZE 10
struct person_st
{
int id;
char name[NAMESIZE];
int age;
struct person_st *link;
};
struct person_st * create()
{
int str,i;
struct person_st *head,*current,*next;
head = (struct person_st *) malloc (sizeof(struct person_st));
printf("您需要添加几个学生?");
scanf("%d",&str);
current=head;
for(i=0;i<str;i++)
{
next = (struct person_st *) malloc (sizeof(struct person_st));
current->link = next;
current = next;
printf("请输入您的学号(01001):姓名:年龄【空格隔开】:");
scanf("%d%s%d",&next->id,next->name,&next->age);
}
next->link=NULL;
return head;
}
int main()
{
struct person_st *p;
p = create();
while(1)
{
printf("%d %s %d",p->id,p->name,p->age);
if(p->link != NULL)
{
p = p->link;
}
else
{
break;
}
}
return 0;
}
运行出现乱码,请教各位 , 程序那里有问题