Here is an overly simplified version of what I am trying to do:
#define LOGDIRECTORY C:\\logs\\
system("mkdir LOGDIRECTORY");
However the preprocessor, instead of swapping out the defined name is not. Instead the system command actually thinks LOGDIRECTORY is the name, and thus is shooting me errors when starting the program.
I know it’s wrong and there must be something I can do with the " marks or other characters to specify what I want, but I can’t figure it out. I don’t want to hardcode the directory and file names because someone may want to change them in the future and it would be much easier to change a define than the whole function etc.
PS, I am coding this in plain C.
In C, you can do simple string concatenation by writing two string literals with no operator in between.
"A" "B"will be converted to"AB"at compile time. You can also use this for splitting a long string to multiple lines.To convert the define to a proper string, use the pound sign (#) in a macro or skip the whole thing and include the quotes in the define itself.