#include #include #include typedef void (*initfunc)(void); typedef int (*guessfunc)(int); int main(void) { void* handle; initfunc init; guessfunc guess; int num; char line[256]; int result; handle = dlopen("./libguess.so", RTLD_NOW | RTLD_GLOBAL); if (!handle) return -1; init = (initfunc) dlsym(handle, "init"); guess = (guessfunc) dlsym(handle, "guess"); init(); do { fgets(line, 255, stdin); num = atoi(line); result = guess(num); if (result == 0) printf("Gotcha!\n"); else if (result > 0) printf("Too high!\n"); else if (result < 0) printf("Too low!\n"); } while (result); return 0; }