I want to do a file operation and write file to the folder which is something in $(USER) directory.
// static const char* out_filename = "/data/panda/output/out.yuv"; //NO ERROR
static const char* out_filename = "/data/$(USER)/output/out.yuv"; // ERROR
FILE* fs_dmp= fopen(out_filename, "w+");
if (NULL == fs_dmp) {
printf("ERROR creating output file %s\n", out_filename);
exit(1);
}
When I am running the c code,
Error: ERROR creating output file /data/output/out.yuv
UPDATE0:
After @Fred Larson suggestion, I tried to use getenv()
code to get the USER name (environment variable) but my goal is to use this USER name and create a username folder in /data/$(USER)
this way.
UPDATE1:
I tried using sprintf this way :
const char *env_p = getenv(name);
if (env_p) {
printf("%s = %s\n", name, env_p);
}
char out_sprint_filename[100];
int n = sprintf(out_sprint_filename, "/data/%s/output/out.yuv", env_p);
printf ("Name of file: %s \n", out_sprint_filename);