a
请输入给您指定的函数输调用的参数 afun_par ----------------------------- now call_fun_ptr ----------------------------- call afun:(afun_par) ----------------------------- 请按任意键继续. . . a:用call_fun_ptr调用afun(),b:用call_fun_ptr调用bfun() b 请输入给您指定的函数输调用的参数 bfun_par ----------------------------- now call_fun_ptr ----------------------------- call bfun:(bfun_par) -----------------------------请按任意键继续. . .
/* */#include "common.h"void call_fun_ptr(void(*fp)(char* str),char *str){ puts("-----------------------------"); printf("now %s \n",__FUNCTION__); (*fp)(str);}void afun(char* str){ puts("-----------------------------"); printf("%s%s:(%s)\n","call ",__FUNCTION__,str); puts("-----------------------------");}void bfun(char* str){ puts("-----------------------------"); printf("%s%s:(%s)\n","call ",__FUNCTION__,str); puts("-----------------------------");}int main(int argc,char* argv[]){ char ch='\0'; char str[81]={0}; void ((*fun_ptr[2]))(char*)={afun,bfun}; printf("a:用call_fun_ptr调用afun(),b:用call_fun_ptr调用bfun()%\n"); scanf("%c",&ch); printf("请输入给您指定的函数输调用的参数%s\r\n",str); scanf("%s",str); if('a'==ch) call_fun_ptr(*fun_ptr[0],str); else if('b'==ch) call_fun_ptr(*fun_ptr[1],str); else printf("输入字符无效\n"); system("pause"); return 0;}