函数指针数组

阅读 59

2022-01-04

#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;
};


 

精彩评论(0)

0 0 举报