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

}

相关推荐
十月的皮皮11 小时前
C语言学习学习笔记20260704-中缀表达式求值(双栈法)
c语言·笔记·学习
wuminyu11 小时前
markword在高并发场景下变化剖析
java·linux·c语言·jvm·c++
星夜夏空9911 小时前
C++学习(1) ——C与C++
c语言·c++·学习
wuyk55512 小时前
25. 函数指针表:用查表替代 switch-case,打造高效可维护的嵌入式状态机
c语言·stm32·单片机·mcu·51单片机
时间的拾荒人1 天前
C语言字符函数与字符串函数完全指南
c语言·开发语言
持力行1 天前
C/C++ 中的 char*:它标识数组吗?为什么能用下标访问?
c语言·c++
小陈的代码之路1 天前
回文链表(LeetCode 234)C语言最佳解题思路
c语言·leetcode·链表
aaaameliaaa1 天前
计算斐波那契数(递归、迭代)(1,1,2,3,5.....)
c语言·开发语言·笔记·算法·排序算法
zhangfeng11331 天前
算子开发 Overwrite 覆盖/替换模式 Accumulate 累加模式,性能对比 memset错误 bat_alloc 错误
c语言·人工智能·gnu·算子开发
SuperByteMaster1 天前
JLinkDevices.xml FLM文件路径不对
c语言