LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-26-2011, 05:39 AM   #1
anon02
Member
 
Registered: Aug 2011
Posts: 223

Rep: Reputation: Disabled
(C) How would I save a file to a different folder which is the users home?


I am trying to make my program save the settings in /home/USERNAME/.crimson_swarm, and to do this from within /usr/bin. The only issue is that if my username was ben, it would be /home/ben. If it was paul however, it would be /home/paul.

My question is, how can C access the users home directory from a different location?

Also, if anyone knows, what is the environment variable for Windows?
 
Old 10-26-2011, 07:08 AM   #2
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by ThatPerson View Post
My question is, how can C access the users home directory
Code:
getenv("HOME")
Note that it's possible for it to fail if the $HOME variable is not set (not that it's likely, but I would make it exit cleanly if that happens).
 
Old 10-26-2011, 07:19 AM   #3
anon02
Member
 
Registered: Aug 2011
Posts: 223

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by MTK358 View Post
Code:
getenv("HOME")
Note that it's possible for it to fail if the $HOME variable is not set (not that it's likely, but I would make it exit cleanly if that happens).
How would I use that in code? Would it be:
Code:
home * getenv("HOME");
Or are there other methods?
 
Old 10-26-2011, 07:27 AM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by ThatPerson View Post
How would I use that in code? Would it be:
Code:
home * getenv("HOME");
Or are there other methods?
I have no idea what you mean here, "home" is not a type.

Anyway, if you're not sure how to use it, just search: https://duckduckgo.com/?q=c+getenv
 
Old 10-26-2011, 07:30 AM   #5
anon02
Member
 
Registered: Aug 2011
Posts: 223

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by MTK358 View Post
I have no idea what you mean here, "home" is not a type.

Anyway, if you're not sure how to use it, just search: https://duckduckgo.com/?q=c+getenv
Ah, thanks. By 'home', I meant it as in 'char'. I managed to get it work... but only for linux. I tried compiling it for Windows, yet getenv("HOME") returns null. Is there a way to get it for Windows?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Restricting users to their home folder supervillan Linux - Newbie 2 04-08-2009 11:47 AM
Copying to a folder in a users $HOME dir. jaredhanks Linux - Newbie 4 05-03-2008 12:17 AM
save web page results in a file and a folder. Whats the folder for? geeyathink General 2 01-30-2008 06:57 AM
back up users home folder? paperplane Linux - Newbie 5 12-27-2007 03:45 PM
Home Folder for new users CatSC Red Hat 3 11-29-2003 04:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration