As extra credit for a homework assignment I'm working on, we have to try and call win()
by providing input to the executable of the below code (we can't change the code). We have to provide a number n
and a value for target
, which is then executed. I know what the value of n
is. I'm not super well-versed in C, but I was looking through many other questions on here about using function pointers, and I thought passing in &win
would work, but that just prints Third challenge
an excessive amount of times and then seg faults. Can someone point me in the right direction, or to more resources so I could better understand how the function pointer is working in this program?
typedef void (*funcptr_t)();
int win()
{
printf("Great Job\n");
exit(0);
}
int main()
{
int n = 0;
unsigned long long target;
printf("Third challenge\n");
scanf("%d", &n);
scanf("%llu", &target);
if (n == 0xc0decafe) {
funcptr_t funcptr = (funcptr_t)target;
funcptr();
}
}