From: Luciano Moreira - ht <lucianomx@hotpop.com>
To: linux-c-programming <linux-c-programming@vger.kernel.org>
Subject: Re: HOME directory
Date: Mon, 25 Apr 2005 13:50:34 -0300 [thread overview]
Message-ID: <426D1FDA.2020709@hotpop.com> (raw)
Yeah ! You need to read the desired environment variable (like HOME),
using a API like "|char *getenv(const char */name/);".
After read, you shall concatenate the 2 strings:
char *pHome;
char *pMyDir="mydir/mysubdir";
char sFullPath[_MAX_PATH];
pHome = getenv("HOME");
sprintf(sFullPath, "%s/%s", pHome, pMyDir);
WARNING: "sprintf()" isn't the faster way to build a concatenated
string. If you'll need to repeat this in a long loop, try another way
using only a single call to "strcat()".
Luciano
|
HIToC escreveu:
>Hello all!
> I am writing a piece of code that makes files, open directories in my
>HOME directory. All worked well until I changed the name of my HOME dir.
>To make the code portable I tried with use of '~' character:
>
> const char* filename = "~/file.txt";
> ofstream my_file(filename, ios::out);
>
>but this solution does not work.
>Have you any suggestion to find the path of the current home directory or
>the current user name?
>
>Thanks for any suggestion.
>
>
next reply other threads:[~2005-04-25 16:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-25 16:50 Luciano Moreira - ht [this message]
-- strict thread matches above, loose matches on Subject: below --
2005-04-28 12:28 HOME directory HIToC
2005-04-25 16:27 HIToC
[not found] ` <426D1DC8.2080900@hq.ntsp.nec.co.jp>
2005-04-25 16:42 ` Ron Michael Khu
2005-04-25 16:46 ` Ron Michael Khu
2005-04-25 16:43 ` Benjamin Machuletz
2005-04-25 16:59 ` Richard Nairn
2005-04-25 17:05 ` Steve Graegert
[not found] ` <426D38D3.5060901@tlen.pl>
[not found] ` <6a00c8d505042511529bd72c8@mail.gmail.com>
2005-04-26 11:26 ` Adam Dyga
2005-04-25 17:06 ` Glynn Clements
2002-06-03 9:56 home directory Кузнецова Нина
2002-06-03 10:32 ` Nicolas Costes
[not found] ` <3CFC76FF.F41AB199@ns.kinetics.nsc.ru>
2002-06-04 9:25 ` Nicolas Costes
2002-06-04 12:16 ` Milan P. Stanic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=426D1FDA.2020709@hotpop.com \
--to=lucianomx@hotpop.com \
--cc=linux-c-programming@vger.kernel.org \
--cc=lucianolnx@ig.com.br \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.