I have this function:
void func(int a, int b, char s, FILE *fp, int flag)
and i want to use the function’s args based on the flag. For example:
func(num, NOTHING, NOTHING, file, 1)func(num, othernum, NOTHING, NOTHING, 2)
and on the function this_is_function i want to have:
void func(int a, int b, char s, FILE *fp, int flag){
if(flag == 1){
/* use a and file */
}
if(flag == 2){
/* use a,b */
}
/* etc etc */
}
i would like to know if it is possible and how to do this!
Thanks in advance 🙂
You can pass
0tointandcharandNULLfor pointers when you call the function and the arguments are not used.You can also use variadic functions. Variadic functions are functions with a variable number of arguments.