C语言返回函数指针函数的示例代码
作者:互联网
#include <stdio.h> #include <string.h> int CE(char *c, char *e){ if (strcmp(c, "你好") == 0) { strcpy(e, "Hello\n"); return 1; } strcmp(e, "Sorry\n"); return 0; } int EC(char *e, char *c){ if (strcmp(e, "Hello") == 0) { strcpy(c, "你好\n"); return 1; } strcmp(c, "对不起\n"); return 0; } // 返回函数指针的函数 int (*frp(int i))(char *, char *){ if(i == 0) return CE; if(i == 1) return EC; return NULL; } int main() { char result[100]; frp(0)("你好",result); printf("%s", result); frp(1)("Hello", result); printf("%s",result); printf("over!\n"); return 0; }
标签:return,示例,int,C语言,char,result,printf,函数指针,strcmp 来源: https://www.cnblogs.com/sidianok/p/15371300.html