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

}

相关推荐
AI thought1 天前
【转】C语言中 -> 是什么意思?
c语言·位移运算符·右移赋值·无符号整数·算术右移
qeen871 天前
【C++】类与对象之类的默认成员函数(二)
android·c语言·开发语言·c++·笔记·学习
wuminyu1 天前
Java锁机制之park和unpark源码剖析
java·linux·c语言·jvm·c++
asdfg12589631 天前
C 语言中产生伪随机数的标准做法
c语言·开发语言
玖玥拾1 天前
C/C++ 基础笔记(十一)类的进阶
c语言·c++·设计模式·
Soari1 天前
llama.cpp更新(b9553):LLM inference in C/C++,本地和云端实现高性能大模型推理
c语言·c++·llama
2601_961194021 天前
考研资料电子版|去哪找|网盘
java·c语言·c++·python·考研·php
十月的皮皮1 天前
C语言学习笔记202606008- 三角形判断(3种方法)
c语言·笔记·学习
c++之路1 天前
C/C++ 全链路编译工具汇总
c语言·开发语言·c++
凡人叶枫1 天前
Effective C++ 条款02:宁可以编译器替换预处理器
java·linux·c语言·开发语言·c++