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

}

相关推荐
揽星河..13 小时前
【C语言】指针
c语言·开发语言
蹊黎1 天前
Linux 下用 C 语言实现进度条
linux·c语言·单片机
爱聊灵光的维C1 天前
从看见世界到重构认知:在视觉与硬件的交汇处,寻找我们这代人的北极星
c语言·物联网·计算机视觉·重构·硬件工程·射频工程
AI+程序员在路上1 天前
RV1126B 上支持的模型及全流程应用--从CNN及语音到 LLMVLM 与跨平台选型
linux·c语言·人工智能
揽星河..1 天前
【C语言】扫雷游戏
c语言·算法·游戏
冻柠檬飞冰走茶1 天前
PTA刷题集之Airline Routes(C语言实现)
c语言·开发语言·数据结构·算法
冻柠檬飞冰走茶1 天前
PTA刷题集之Battle Over Cities - Hard Version(C语言实现)
c语言·开发语言·数据结构·算法
Lxx_Zw2 天前
串口命令如何从字符串长成协议:帧头、长度、校验和与状态机
c语言·stm32·单片机·嵌入式硬件
wuminyu2 天前
JVM执行引擎学习总结:热点字节码编译成本地机器码
java·linux·c语言·jvm·c++
佳得动2 天前
编译和链接的认识(C语言)
c语言·开发语言