I'm running into an odd problem with concatenating or printing strings. I have a char * that can be set to one of a few values of string literal.
char *myStrLiteral = NULL;
...
if(blah)
myStrLiteral = "foo";
else if(blahblah)
myStrLiteral = "bar";
And I have some other strings that I get from library functions or that are concatenations of input - they're either malloc'ed or stack variables. When I try to print (or concatenate using strcpy() and strcat(), the result is the same), even though I print the string literal last, it prints over the initial characters of the entire string I'm constructing or printing.
/* otherString1 contains "hello", otherString2 contains "world" */
printf("%s %s %s\n", otherString1, otherString2, myStrLiteral);
/* prints "barlo world" */
Am I misunderstanding something about string literals in C?