C doesn't automatically replace occurences of an identifier with its value. The preprocessor does that, though. You could define a macro
#define directory "/tmp/hello.txt"
and then do
int s = system("echo password | gpg -c --passphrase-fd 0 " directory);
This concatenates the strings at "preprocessing time", even before compile time. Another way would be to use strncat
to concatenate the two strings at runtime:
char str[128] = "echo password | gpg -c --passphrase-fd 0 ";
strncat(str, directory, sizeof(str) - strlen(str));
To be able to reappend the string you could store the strlen(str)
, write a null byte to it every time and then call strncat
:
void append(const char* app) {
static const size_t len = strlen(str);
str[len] = '\0';
strncat(str, app, sizeof(str) - len);
}