|
楼主 |
发表于 2013-12-20 17:20:10
|
显示全部楼层
#include<stdio.h>
#define M 5
#define NULL 0
#define LEN sizeof(struct worker)
struct worker
{
char name[20];
int age;
float wages;
struct worker *next;
};
int n;
struct worker *creat()
{
int i;
int wages;
struct worker *head;
struct worker *p1, *p2;
n = 0;
head = p1 = ( struct worker *)malloc(LEN);
head->next = NULL;
for ( i = 0; i < M; i++ )
{
p2 = ( struct worker *)malloc(LEN);
printf("input name & age & wages\n");
scanf("%s,%d,%d", p2->name, &p2->age, &wages);
n++;
p1->next = p2;
p1 = p2;
}
p1->next = NULL;
head->age = n;
return(head);
}
void output( struct worker *head )
{
struct worker *p1;
int i = 1;
p1 = head->next;
do
{
printf("%s,%d,%d\n",p1->name,p1->wages);
p1 = p1->next;
i++;
}
while ( p1 != NULL );
}
main()
{
struct worker *head;
head = creat();
printf("there are %d structs\n",n);
output (head);
} |
|