Retrieve the enviromental variable value using the function getenv.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fp;
char fname[280];
strcpy(fname, getenv("USERPROFILE"));
strcat(fname, "\\Documents\\hello.txt");
fp=fopen(fname,"w");
if(fp!=NULL){
fprintf(fp,"Hello, world!\n");
fclose(fp);
}
else printf("can't open the file\n");
return 0;
}