Function with a Function Parameter in C | [-Wint-conversion] ? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

Function with a Function Parameter in C | [-Wint-conversion] ?

I want to make a function_caller(func, amount) which calls the 'func', 'amount' times. (in C) However, the function gets called only once when I'm asking for 4. |81|warning: passing argument 1 of 'func_caller' makes pointer from integer without a cast [-Wint-conversion]| https://code.sololearn.com/c9a20A12A100

17th Feb 2021, 11:23 AM
Fatih Yalçın
Fatih Yalçın - avatar
2 Antworten
+ 2
In line 23 remove int, it makes part variable inside the if statement local. In line 68 it's a wrong way to pass a function as an parameter. You should use function pointer. Function pointer is a pointer to function. It's the only way to pass function around. A function pointer is basically like: data_type (*func_name)(arg-data_type1, arg-data_type2, ...) Your dna() has 1 char[] and 1 int. You will also need 2 extra parameter for the function to be passed. The definition will be: void func_caller(int (*func)(char[], int), char arg1[], int arg2, int times) [For better explanation of function pointer you can search online] And to call func inside the func_caller(), it will be func(arg1, arg2). In line 78 remove the address operator. Use scanf("%s", d); In line 81 as the declaration of func_call() is slightly changed, the correct way to call func_call() will be func_call(dna, d, 16, 4)
17th Feb 2021, 11:40 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Thank you so much.
17th Feb 2021, 11:59 AM
Fatih Yalçın
Fatih Yalçın - avatar