#include "stdio.h"
void TheShow()
{
printf("1.xiao\n");
}
void Zootopia()
{
printf("2.feng\n");
}
void Inteste()
{
printf("3.xing\n");
}
void TheLegendof()
{
printf("4.hai\n");
}
void TheMatrix()
{
printf("5.hei\n");
}
int main()
{
void(*p[5])()={TheShow,Zootopia,Inteste,TheLegendof,TheMatrix};
char list[20];
scanf("%s",list);
for (int i=0;list[i]!='\0';i++)
{
char num=list[i];
num=num-'0';
num--;
(*p[num])(); //可简化为,p[num]();,c语言支持这两种书写方式
}
return 0;
};
该代码示例展示了如何使用函数指针数组来调用不同的函数。通过读取用户输入的字符,转换为整数并作为索引,它依次执行对应编号的函数,输出预定义的字符串。
1202

被折叠的 条评论
为什么被折叠?



