Well, this is the expected behavior. You are supposed to use parameter placeholders to build your commands. Please have a look at the documentation.
Extracted from hiredis source code:
/* Format a command according to the Redis protocol. This function
* takes a format similar to printf:
*
* %s represents a C null terminated string you want to interpolate
* %b represents a binary safe string
*
* When using %b you need to provide both the pointer to the string
* and the length in bytes. Examples:
*
* len = redisFormatCommand(target, "GET %s", mykey);
* len = redisFormatCommand(target, "SET %s %b", mykey, myval, myvallen);
*/
If you change your code as follows, it will fix the problem.
reply = redisCommand(c,"RPUSH mylist %s","element 0"); freeReplyObject(reply);
reply = redisCommand(c,"RPUSH mylist %s","element 1"); freeReplyObject(reply);
reply = redisCommand(c,"RPUSH mylist %s","element 2"); freeReplyObject(reply);
Also, I would suggest to systematically test the return codes of hiredis APIs. It may be cumbersome, but it will save you a lot of problems in a later phase of your project.