C语言完美演绎9-16

/* 范例:9-16(以VC++执行,请参考范例光盘源代码中的说明)*/

#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

struct person

{

char name30;

int age;

person *next;

};

person *start, *nowper, *newper; /* 步骤一 */

void main(void)

{

char agestr5; /* 年龄以字符串方式输入 */

clrscr(); /* 清屏 */

do

{

newper = (person *)malloc(sizeof(person));

if (start==0) /* 步骤二 */

start = nowper = newper;

else

{

nowper = start; /* 将目前指针指向开头 */

while(nowper->next != (person *)NULL)

nowper = nowper->next ; /* 找链表尾端 */

nowper->next = newper; /* 将原链表尾指向新节点 */

nowper = newper;

}

printf("\n输入姓名:"); gets(nowper->name);

printf("\n输入年龄:"); gets(agestr);

nowper->age = atoi(agestr);

nowper->next = (person *)NULL; /* 链表尾端指向NULL */

printf("是否继续 是(y)否(n)? ");

}while(getche()!='n');

nowper = start; /* 从头输出 */

clrscr();

do

{

printf("\n姓名:%s 年龄: %d", \

nowper->name,nowper->age);

nowper = nowper->next ; /* 移到下一节点输出 */

}while(nowper != (person *)NULL);

getchar();

}

相关推荐
luj_176835 分钟前
塔防牌:策略与卡牌的智慧碰撞
服务器·c语言·开发语言·经验分享·算法
wuyk5551 小时前
3.链表:用指针串联的动态数据结构
c语言·开发语言·数据结构·链表
Lzh编程小栈2 小时前
【嵌入式底层】SPI超透彻详解:通信原理、四线结构、四种模式、寄存器底层 + 面试全集
c语言·stm32·单片机·面试·职场和发展
凉茶钱3 小时前
【数据结构】堆的应用
c语言·数据结构
Herbert_hwt7 小时前
【C语言基础】常量、选择结构与运算符全解析
c语言·开发语言·算法
WWJA王文举19 小时前
I²C通信完整流程详解:START、地址、ACK、数据、Repeated START和STOP一次讲透
c语言·开发语言
qq_4480111621 小时前
C语言中的动态内存分配
c语言·开发语言·php
动词ing1 天前
【学习笔记】C语言(数组指针与指针数组+字符数组+函数+参数传递+字符串作为形参+递归函数+指针函数+回调函数+结构体嵌套+内存动态分配函数)
c语言·笔记·学习
小雨笙笙1 天前
C语言:变量三属性——存储类型
c语言·开发语言
Navigator_Z1 天前
LeetCode //C - 1192. Critical Connections in a Network
c语言·算法·leetcode