C语言完美演绎8-18

/* 范例:8-18 */

#include <stdio.h>

void procreation(int,void (*run)(char*,int)); /* 以函数指针为参数 */

void slow_run_shoes(char*,int);

void leisure_shoes(char*,int);

void spiked_shoes(char*,int);

void main()

{

int procreation_number; /* 生产项目代号1~3 */

int size; /* 尺寸 */

procreation_number=2;

size=8;

switch(procreation_number)

{

case 1: /* 参数行中传入函数slow_run_shoes的地址*/

procreation(size,slow_run_shoes);

break;

case 2: /* 参数行中传入函数leisure_shoes的地址 */

procreation(size,leisure_shoes);

break;

case 3: /* 参数行中传入函数spiked_shoes的地址 */

procreation(size,spiked_shoes);

break;

default:

printf("停止生产!!!\n");

}

getchar();

}

void procreation(int size,void (*run)(char* material,int size))

{

char* material; /* 质料名称 */

int material_number; /* 质料代号1~3 */

material_number=3;

switch(material_number)

{

case 1:

material="布";

break;

case 2:

material="兽皮";

break;

case 3:

material="塑料";

}

(*run)(material,size); /* 调用函数指针 */

}

void slow_run_shoes(char* material,int size)

{

printf("以质料为%s、尺寸为%d来生产慢跑鞋\n",material,size);

}

void leisure_shoes(char* material,int size)

{

printf("以质料为%s、尺寸为%d来生产休闲鞋\n",material,size);

}

void spiked_shoes(char* material,int size)

{

printf("以质料为%s、尺寸为%d来生产钉鞋\n",material,size);

}

程序执行结果:

以质料为塑料、尺寸为8来生产休闲鞋

相关推荐
aramae4 小时前
模拟实现strcmp()(C语言)
c语言·开发语言·后端
91刘仁德12 小时前
C++ 继承和多态 设计模式
c语言·c++·笔记
码行山野赴时序归途13 小时前
链表家族收官篇:循环链表
c语言·开发语言·数据结构·链表
库玛西13 小时前
哈夫曼树与前缀编码:数据压缩的贪心核心
c语言·c++·笔记·考研
雷✘14 小时前
C 语言预处理中的宏展开、条件编译与头文件保护
c语言
aramae14 小时前
模拟实现memset()(C语言)
c语言·开发语言·后端
phltxy15 小时前
C语言结构体
c语言
库玛西15 小时前
数据结构与算法之美:树、森林与二叉树全解析
c语言·数据结构·笔记·考研·算法·学习方法
2601_9555181815 小时前
如何学好C语言:从入门到精通,掌握编程基石
c语言·指针·项目实战·调试技巧·编程基础
是隼人15 小时前
buuctf-pwn ciscn_2019_sw_1(32位只有一次格式化机会)题解(学习过程持续更新)
c语言·学习·安全·pwn入门·ctf入门