: Hi, I'm writing my first "big" GUI program.
: In this program, I store some preferences in a rc file. Somehow, I just
: can't place it in the user's homedir.
: When I use:
: FILE *fp;
: fp = fopen(".prefs.rc", "r");
: it works fine. Although when I use
: fp = fopen("~/.prefs.rc", "r"); it somehow cannot find the file.
: What's wrong? Can't I use the tilde (~) in a filename? Or should it be
: preceded by some escape character? (In case it matters: I use Linux.)
~ notation is expanded by the shell and is supported by the Csh and
POSIX compliant shells (POSIX sh, ksh, bash, etc).
Well, since you are using Linux, bash should be the shell used by
system() and popen() and bash will expand ~ notation, so you could
rewrite the fopen as a popen:
if (NULL == (pp = popen("/path/to/cat ~/.prefs.rc", "r")))
{
perror("popen ~/.prefs.rc");
exit(1);
}
or some such. Be sure you don't forget the pclose or you'll leave a zombie
process* around. I've used this trick for years on HP-UX 9/10
which uses the POSIX sh for system and popen. I would fully qualify
the path to cat, however, to discourage mischief.
: Any help would be greatly appreciated.
: Thanks in advance,
: Erik van Zijst
: --
: http://www.veryComputer.com/~icehawk (MegaLAN, Internet and Music Party!)
: ICQ UIN number: 4545632
--
Dan Mercer
Opinions expressed herein are my own and may not represent those of my employer.