1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| [root@localhost source]# cat main.c #include "string.h" #include "stdio.h"
int fun_B(int a, int b, void* context) { char *str = (char*)context;
const char *p = "World Hello World Hello";
strncpy(str, p, strlen(p));
return 0; }
int fun_A(int a, int b, int (*callback)(int a, int b, void *context), void *context) {
callback(a, b , &context);
printf("a=%u b=%u\n", a ,b);
return 0; }
int main(int size, char **list) { char str[] = "Hello World";
fun_A(1, 2,fun_B, str);
return 0; }
[root@localhost source]#
|