Here is my simple working program:
Code:
#include <stdio.h>
#define CHANGE_STR(old_str, new_str) (old_str = new_str)
int main(void)
{
char *msg = "This is old message.";
printf("%s\n", msg);
CHANGE_STR(msg, "This is my new message.");
printf("%s\n", msg);
return 0;
}
But I have a question: how to make it work if macro would be replaced with an average function?
Like this:
Code:
void CHANGE_STR(char *old_str, char *new_str)
{
/*
Some code here.
I have tried several tricks but so far nothing seems to work.
*/
}
I completely understand that using CHANGE_STR as function is completely irrational (since macro does the trick perfectly). But still, is it possible at all? If yes, then how to make it work? I'd just like to understand the logic of the C as deeply as possible.