Answers for "call a function inside argument of another function c"

C
1

call a function inside argument of another function c

int main (void) {
  Repeat(SayHello,4);
  Repeat(SayGoodbye,2);
}

void Repeat(void (*fct)(int), int i) {
  for (int j=0, j<i; j++) {
    (*fct)(j);
  }
}

void SayHello(int nbr) {
  printf("Hello n.%d\n", nbr);
}
void SayGoodbye(int nbr) {
  printf("Goodbye n.%d\n", nbr);
}

Result :
Hello n.0
Hello n.1
Hello n.2
Hello n.3
Goodbye n.0
Goodbye n.1
Posted by: Guest on November-05-2020
2

passing a function as an argument in c

void func ( void (*f)(int) ) {
  for ( int ctr = 0 ; ctr < 5 ; ctr++ ) {
    (*f)(ctr);
  }
}
Posted by: Guest on July-21-2020
0

passing a function as an argument in c

void func ( void (*f)(int) );
Posted by: Guest on July-21-2020

Code answers related to "call a function inside argument of another function c"

Code answers related to "C"

Browse Popular Code Answers by Language