-3

I have following function

unsigned char foo(unsigned char(*fun[])(unsigned char *))

How to pass an argument to this function?

LPs
  • 16,045
  • 8
  • 30
  • 61
Atul Charate
  • 31
  • 1
  • 5

1 Answers1

1

That function prototype declare a function that takes as parameter an arraay of functions pointer. Each function pointer must have type unsigned char function_name(unsigned char *)

For example you can do: (changed passed pars to ease the example)

#include <stdio.h>

unsigned char dummy(char *dummypar)
{

    printf("Dummy: %s\n", dummypar);

    return 0;
}

unsigned char dummy2(char *dummypar)
{
    printf("Dummy2: %s\n", dummypar);

    return 0;
}

unsigned char foo(unsigned char(*fun[])(char *))
{
    char *test = "test";
    size_t i = 0;

    while (fun[i] != NULL)
    {
        fun[i](test);

        i++;
    }

    return 0;
}

unsigned char(*array[])(char *) = { dummy, dummy2, NULL };

int main ( void )
{
    foo(array);
}
LPs
  • 16,045
  • 8
  • 30
  • 61