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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -