1
I need it passed through argv[]
, in the main function, the name of a function that will be called by the same.
I can’t make comparisons of strings, then I must make the call with variables.
Here is my code:
typedef void (*func)(void);
void A (void){ printf("*funcao A*\n"); }
void B (void){ printf("*funcao B*\n"); }
void fun(func fc){
fc();
}
int main(int argc, char *argv[]){
int i;
for(i = 1; i < argc; i++){
fun(argv[i]);
}
system("PAUSE");
return 0;
}
This way the algorithm compiles but does not execute.
I can compile, but not even enter the cycle
for
– Jorge B.
argc
is not zero-based? In that case thefor
has to start ati = 0
.– Piovezan
I already started in i = 1 because in argv[0] you have the file directory.
– FightForWhat
If the exercise asks for pass the name of a function, I find it hard to escape making comparisons of strings at some point. It gives an investigation into this requirement.
– karlphillip
@Fightforwhat Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on all the posts on the site as well. Did any help you more? You need something to be improved?
– Maniero