my program in C has some functionality (#obviously). The program gets input from the user, this user can then choose different implementations, e.g. myProgram -V1, or myProgram -V2 ...
This specification of -V1, -V2, ... decides how the function performs a particular calculation.
E.g..
for (int i = 0; i < len; i++) {
i += myFunctionWhichChangesBehaviorOnUserInput(arr[i]);
}
Now I don't want to create a separate function for each V and then change the respective myFunctionWhichChangesBehaviorOnUserInput() function there.
I know you can do it this way in java.
interface Compute {
double compute(double n);
}
... some imple of Compute
class Task {
Compute compute;
void setCompute(Compute c) {this.compute = c}
double doMyStuff(double[] arr) {
double n = 0;
for (int i = 0; i < arr.length; i++) {
n += compute.compute(arr[i]);
}
return n;
}
}
How can you implement this in C, must be possible somehow.