I\'m a little confused over how to declare a function pointer in a header file. I want to use it in main and a file called menus.c and declare it in menus.h I assume. We wan
It's often helpful to use typedef with function pointers, so you can name the type to something descriptive:
typedef void (*MenuFunction)(int);
Then you would have a global variable of this type, probably in menus.c, and declared (with extern) in menus.h:
static void my_first_menu_function(int x)
{
printf("the menu function got %d\n", x);
}
MenuFunction current_menu = my_first_menu_function;
From main.c, you can then do:
#include "menu.h"
current_menu(4711);
to call whatever function is currently pointed at by current_menu.