复习C语言系列二:动态调用函数指针数组
2013-11-18 21:36
501 查看
a:用call_fun_ptr调用afun(),b:用call_fun_ptr调用bfun()
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)
-----------------------------
请按任意键继续. . .
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; }
相关文章推荐
- 复习C语言系列二:动态调用函数指针数组
- C语言 指针高级:函数回调之动态调用
- C语言系列之 指针与数组总复习视频教程
- C语言指针系列 - 一级指针.一维数组,二级指针,二维数组,指针数组,数组指针,函数指针,指针函数
- C语言指针系列 - 一级指针.一维数组,二级指针,二维数组,指针数组,数组指针,函数指针,指针函数
- C语言基础之函数、虚拟键盘的使用、数组、指针、动态申请内存、内存泄漏
- C语言:利用指针和函数调用编写字符串拷贝函数strcpy
- 通过函数指针动态调用 dll 中的函数
- C语言之数组专题:数组指针、指针数组、数组做函数参数退化、数组名、数组类型
- C语言之指针、数组和函数
- C语言中多维数组的常见动态分配方式及其在函数参数传递时的应用
- [C语言]指针数组与数组指针,函数指针与指针函数
- 关于C语言声明、指针、数组、函数、typedef等等的一通“超级扯”
- C语言中 数组作为函数形参传递相当于指针,在函数中不能得到数组长度,只能得到指针长度4
- [C语言]指针数组和指针数组|函数指针和指针函数
- C语言之指针、数组和函数
- 8.6函数调用与数组和指针的运用
- C语言 函数指针三(反向调用)
- 水滴石穿C语言之指针、数组和函数
- C语言复习之指针数组