Article 4SHRX open new or existing file and write to it. not working like I need it too.

open new or existing file and write to it. not working like I need it too.

by
BW-userx
from LinuxQuestions.org on (#4SHRX)
If I witre it that standard example way to open a file that works, but if I tell it to open a file using a path gotten from code, it does not work. the program does not fail (exit) on a file that is not there, it continues to run even thought it did not actually create and or open an existing file by the same name.

I get user home dir via what is in the code, add that path to a file name open the file, that is not there. it creates it (supposedly). but when I look it is not there at all.
Code:
struct passwd *p;
char *uhome = NULL;
uid_t uid;

if ((p = getpwuid(uid = getuid())) == NULL)
perror("getpwuid() error");
else {
uhome = p->pw_dir;
}
char configfile[21] = "/mhsetrootimagefile";
strcat(uhome,configfile);

FILE *fptr;

// this one not working -> //fptr = fopen("uhome", "wr+");

fptr = fopen("ThisFile", "w+");
if (fptr == NULL) {
fprintf(stderr,"cannot open config file\n");
exit(1);
}
printf("file = %s\n",uhome);Code:file = /home/userx/mhsetrootimagefile

[userx@FreeBSD12 ~]$ ls /home/userx/mhsetrootimagefile
ls: /home/userx/mhsetrootimagefile: No such file or directorywhat is the proper way to cause the code to create if not there or open if there in a specified location?

IT is not because in here that code is commented out.latest?d=yIl2AUoC8zA latest?i=DjfULIK4qtU:6EpCwdSsR_o:F7zBnMy latest?i=DjfULIK4qtU:6EpCwdSsR_o:V_sGLiP latest?d=qj6IDK7rITs latest?i=DjfULIK4qtU:6EpCwdSsR_o:gIN9vFwDjfULIK4qtU
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments