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来生产休闲鞋

相关推荐
牧以南歌〆3 小时前
数据结构<三>单循环链表
c语言·数据结构·算法·链表
麻瓜老宋4 小时前
AI开发C语言应用按步走,我的基础开发环境
c语言·开发语言
见叶之秋4 小时前
C细节补充
c语言·开发语言
Lzh编程小栈4 小时前
嵌入式深度精讲|STM32引脚全方位底层原理、配置逻辑、硬件规范、高频面试题
c语言·stm32·单片机·嵌入式硬件
天空'之城13 小时前
C 语言工业级通用组件手写 04:阻塞队列
c语言·嵌入式开发·阻塞队列·多线程开发
dtq042416 小时前
C语言-结构体详解
c语言·开发语言·学习
Rainy Blue88317 小时前
C转C++速成
c语言·c++·算法
exm-zem19 小时前
从C语言到C++:C++入门1
c语言·c++
牧以南歌〆21 小时前
数据结构<八>链式队列
c语言·数据结构·算法
无相求码1 天前
数组越界为什么有时候不崩溃?VS2013 下栈上变量的幽灵布局解密
c语言·后端