Sure - just use a "callback":
1. Your library function has a parameter that's a pointer to a function.
2. You program that calls the library function defines the actual function
(which is the "callback function
.
3. When your program calls the library function, it passes the callback.
4. Your library invokes the callback.
Examples of "callbacks" are numerous:
* signal handlers (in the Linux world)
* WinProc (in "classic Windows" programming)
* GTK+ event handlers
* etc etc
Try "man signal", for example.