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 36 37 38 39 40 41 42 43 44 45 46 47 48
| #include <stdio.h>
#include <stdlib.h>
typedef void (*t_func)(char*);
// Forward Declaration
void caller(t_func, char*, char*);
t_func give_me_the_func(char* debug_str, char* first_str, char* seconde_str) {
void toto01(char *s) {
if (s != NULL) {
printf("%s\n", s);
} else {
printf("%s\n", debug_str);
}
}
void toto02(char *s) {
printf("%s\n", s);
}
toto01(NULL);
caller(toto02, first_str, seconde_str);
return toto02;
}
int main(int argc, char* argv[])
{
t_func func01 = give_me_the_func("main - debug: take the first func", "first func: 01", "first func: 02");
t_func func02 = give_me_the_func("main - debug: take the second func", "second func: 01", "second func: 02");
caller(func01, "kaboum: 01", "kaboum: 02");
return EXIT_SUCCESS;
}
void caller(t_func f, char* first_str, char* seconde_str) {
(*f)(first_str);
(*f)(seconde_str);
} |
Partager