键盘输入造链表1

#include <stdio.h>
#include <malloc.h>
//键盘输入造链表

struct wyq{
char name[100];
int age;
char address[100];
struct wyq*next;
};

int main()
{
struct wyq*
head;
struct wyq*p;
struct wyq*q;
int i;

head=(struct wyq*)malloc(sizeof(struct wyq));
if(NULL==head){
printf("没有申请成功");
exit(-1);
}

printf("输入链表节点内容:\n");
printf("姓名->");
scanf("%s",head->name);
printf("年龄->");
scanf("%s",head->age);
printf("地址->");
scanf("%s",head->address);
head->next=NULL;


p=head;
q=head;

printf("1;继续;2停止\n");
scanf("%d",&i);
while(i==1) {
p=(struct wyq*)malloc(sizeof(struct wyq));
printf("输入链表节点内容:\n");
printf("姓名->");
scanf("%s",p->name);
printf("年龄->");
scanf("%s",p->age);
printf("地址->");
scanf("%s",p->address);
p->next=NULL;

q->next=p;
q=p;

printf("1;继续;2停止\n");
scanf("%d",&i);

if(i==2){
break;
}
}


return 0;
}

posted @ 2016-06-07 17:45  wangyq0517  阅读(169)  评论(0编辑  收藏  举报