So I was having some fun with c when I tried this:
#include <stdio.h>
#include <string.h>
typedef void (*Function)(char *);
void helloWorld(char *);
void execute(Function, char *);
Function func;
int main(void){
char *message = "StackOverflow";
execute(helloWorld, message);
printf("%s", message);
return 0;
}
void helloWorld(char *message){
printf("HelloWorld, %s.\n", message);
message = "DONE";
printf("[%s]\n", message);
}
void execute(Function function, char * msg){
func = function;
func(msg);
}
Apparently I am not able to use pointers - which I used as parameter - as return value of pointer functions.
Well, can someone explain this behavior? How can I get return value(s) of void function?
const char*with string literals. Also, arguments are passed by value in C. Thereforechar**works (I read your answer.)(void)is the correct way.