|
发表于 2013-12-10 14:06:47
|
显示全部楼层
你还是至尊会员?!好好去学习吧。- #include<stdio.h>
- #include<ctype.h>
- #include<stdlib.h>
- typedef struct stu
- {
- char name[10];
- char address[10];
- char phone[15];
- struct stu* next;
- }node;
- void init(node** head)
- {
- (*head)=(node*)malloc(sizeof(node));
- (*head)->next=NULL;
- }
- void creat(node** head)
- {
- node *p,*q;
- char ch;
- p=(*head);
- printf("name address phone:\n");
-
- q=(node*)malloc(sizeof(node));
- scanf("%s %s %s",q->name,q->address,q->phone);
-
- q->next = p->next;
- p->next = q;
- }
- void output( node n )
- {
- node *tmp , *middle;
- tmp = n.next;
-
- while( tmp )
- {
- printf("name:%s address:%s phone:%s\n" , tmp->name , tmp->address , tmp->phone );
- middle = tmp;
- tmp = tmp->next;
- free(middle);
- }
- free( &n );
- }
- int main()
- {
- node* n;
- int i = 5;
- init(&n);
- while( i-- )
- {
- creat(&n);
- }
- output(*n);
- return 0;
- }
复制代码 |
|