<p>I am using <strong>gcc</strong> for <strong>windows</strong>. The OS is <strong>windows XP</strong>.
How do I import the homepath  variable into my c program so I can write to c:\%homepath%\desktop? I would like to use something similar to:</p>

<p><code>fd = fopen("C:\\%%homepath%%\\desktop\\helloworld.txt","w")</code>;</p>

[{'answer_id': 76010, 'author': 'Lou Franco', 'author_id': 3937, 'author_profile': 'https://Stackoverflow.com/users/3937', 'pm_score': 2, 'selected': True, 'text': '<p>Use getenv() to get the value of an environment variable, then use sprintf or strcat to compose the path.</p>\n'}, {'answer_id': 76146, 'author': 'ljorquera', 'author_id': 9132, 'author_profile': 'https://Stackoverflow.com/users/9132', 'pm_score': 1, 'selected': False, 'text': '<p>Use <code>getenv("homepath")</code> to get the value of environment variable. You should handle the case in which the variable has not been defined (<code>getenv</code> returns <code>NULL</code> in that case).</p>\n\n<p>To compose the path use <code>sprintf</code></p>\n\n<pre><code>char * homepath = getenv("homepath");\n\nif(homepath == null) {\n    /* variable HOMEPATH has not been defined */ \n}\n\nsprintf(path,"%s\\\\desktop\\\\helloworld.txt",homepath);\n</code></pre>\n\n<p>You should make path big enough to accomodate the value <code>homepath</code> and <code>\\\\desktop\\\\helloworld.txt</code>.</p>\n\n<p>Also note the use of <code>\\\\</code> in the string. You can\'t use single <code>\\</code>.</p>\n'}, {'answer_id': 97936, 'author': 'florin', 'author_id': 18308, 'author_profile': 'https://Stackoverflow.com/users/18308', 'pm_score': 0, 'selected': False, 'text': '<p>Note: you actually need to get the value of HOMEDRIVE as well, and prepend that to HOMEPATH.  In many corporate environments, the home directories are kept on large network appliances or servers.</p>\n'}]
['https://Stackoverflow.com/questions/75937', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13461/']