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();

}

相关推荐
Zwawa34 分钟前
PID 的三个参数之外:位置式、增量式和反馈控制
c语言·单片机·嵌入式
slimer1 小时前
11.C 语言 printf 打印函数详解:格式说明符、宽度精度与安全输出
linux·c语言
老花眼猫3 小时前
曼陀罗2-曼陀罗图案自由创制App
c语言·经验分享·青少年编程·课程设计
爱读书的小胖4 小时前
Codewars: A Brave New Wordle(C)解题分析
c语言·数据结构·算法
Escalating_xu4 小时前
【数据结构】顺序表的应用:动态通讯录项目与双指针经典算法
c语言·数据结构·算法
从小白到软工5 小时前
C语言(中)预告
c语言·数据结构·经验分享·ai编程
Logic1016 小时前
C语言/数据结构字符串题解:解压缩“字符+次数“格式——多位数字处理与字符串还原
c语言·数据结构·字符串·模拟·时间复杂度·空间复杂度·算法题
SuperByteMaster7 小时前
while(1){;} 加分号
c语言
Logic1017 小时前
C语言/数据结构位运算题解:异或XOR找出糖葫芦派对中的“独一无二山楂果数量“——只出现一次的数字
c语言·数据结构·数组·位运算·时间复杂度·算法题·异或性质
星恒随风7 小时前
Linux进程信号(一):从Ctrl+C到kill、raise、alarm,深入理解信号的概念与产生原理
linux·c语言·笔记·学习·状态模式