c passes arguments by value, not by reference. You problem is here:
void parse_json_command(char json_command, char *response){
[...]
response = "YOU KNOW";
[...]
}
char *response;
parse_json_command(req, response);
response
is a uninitialized pointer to a string. You are assigning a pointer to a static string to the response
pointer in the function, but that does not modify response
outside of the function, it just changes response
within the function. There are different ways to fix this. Probably the easiest one for a quick fix would be to change the function's prototype to return a char *
instead of void
:
char * parse_json_command(char json_command){
char *response;
[...]
response = "YOU KNOW";
[...]
return response;
}
char *response;
response = parse_json_command(req);
Also, the json_command
argument should probably be a char *
or const char *
, not just a single char
, if you want to pass more than a single byte there.