c - Callback with parameters -
im trying figure out how use callbacks parameters in c. following isnt working. best way archieve it? (passing arguments callback function)
#include <stdio.h> void caller(int (*cc)(int a)) { cc(a); } int blub(int a) { printf("%i", a); return 1; } int main(int argc, char** argv) { caller(blub(5)); return 1; }
you doing call before passing function, not passing callback function itself. try this:
#include <stdio.h> void caller(int (*cc)(int ),int a) { cc(a); } int blub(int a) { printf("%i", a); return 1; } int main(int argc, char** argv) { caller(blub, 1000); return 1; }
Comments
Post a Comment