linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: HOME directory
@ 2005-04-25 16:50 Luciano Moreira - ht
  0 siblings, 0 replies; 10+ messages in thread
From: Luciano Moreira - ht @ 2005-04-25 16:50 UTC (permalink / raw)
  To: linux-c-programming

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.
>  
>


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: HOME directory
@ 2005-04-28 12:28 HIToC
  0 siblings, 0 replies; 10+ messages in thread
From: HIToC @ 2005-04-28 12:28 UTC (permalink / raw)
  To: linux-c-programming

Thank you for every suggestion!





HIToC


		
___________________________________ 
Nuovo Yahoo! Messenger: E' molto più divertente: Audibles, Avatar, Webcam, Giochi, Rubrica… Scaricalo ora! 
http://it.messenger.yahoo.it
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 10+ messages in thread
* HOME directory
@ 2005-04-25 16:27 HIToC
       [not found] ` <426D1DC8.2080900@hq.ntsp.nec.co.jp>
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: HIToC @ 2005-04-25 16:27 UTC (permalink / raw)
  To: linux-c-programming

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.
-- 
With regards,


					HIToC
					hitoc_mail@yahoo.it

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-04-28 12:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-25 16:50 HOME directory Luciano Moreira - ht
  -- strict thread matches above, loose matches on Subject: below --
2005-04-28 12:28 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).