标签:ext size core else #define 链表 define str amp
#include<malloc.h>
#include<stdio.h>
#define LEN sizeof(struct student)
typedef struct student
{
int num;
int age;
float score;
struct student *next;
}stu;
int n;
stu *creat(void)
{
stu *struHead;
stu *struP1;
stu *struP2;
n = 0;
struP1 = struP2 = ( stu *)malloc( LEN );
scanf("%d,%d,%f", &struP1->num, &struP1->age, &struP1->score);
struHead = NULL;
while( struP1->num != 0 )
{
n = n + 1;
if( n == 1 )
{
struHead = struP1;
}
else
{
struP2->next = struP1;
}
struP2 = struP1;
struP1 = ( stu *)malloc( LEN );
scanf("%d,%d,%f", &struP1->num, &struP1->age, &struP1->score);
}
struP2->next = NULL;
return( struHead );
}
void main()
{
stu *p;
stu *head;
head = creat();
p = head;
if( head != NULL )
do
{
printf( "%d,%d,%f\n", p->num, p->age, p->score);
p = p->next;
}while( p != NULL );
}
标签:ext size core else #define 链表 define str amp
原文地址:http://www.cnblogs.com/lanlianggui/p/5989122.html