"请选择"的另类实现!
程序代码:
#include <stdio.h> #include <stdlib.h> typedef void (*types)(void); void counter(int a, types vd[3]); void printx(void); void printy(void); void printj(void); int main(void) { types pp[3]={printx,printy,printj}; int x; printf("请选择一个打印功能\n"); printf("0--printX\n"); printf("1--printY\n"); printf("2--printJ\n"); scanf("%d",&x); counter(x,pp); system("pause"); return 0; } void counter(int a, types vd[3]) { vd[a](); } void printx(void) { printf("XXXXXXXXXXXXXXXXXXXX\n"); } void printy(void) { printf("YYYYYYYYYYYYYYYYYYYY\n"); } void printj(void) { printf("JJJJJJJJJJJJJJJJJJJJ\n"); }