?
Solved

find home directory c++

Posted on 2003-11-30
4
Medium Priority
?
445 Views
Last Modified: 2011-08-18
i am using curl in my program and i need to be able to find the current users home directory, here is a snippet of the curl procedure

char *headerfilename = "logfile";
FILE *headerfile;
headerfile = fopen(headerfilename,"w");
curl_easy_setopt(curl_handle,   CURLOPT_WRITEHEADER ,headerfile);

i need that headerfilename to be /home/USERNAME/logfile

any help would be great

Thanks


 
0
Comment
Question by:nutterx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 24

Expert Comment

by:shivsa
ID: 9846640
u can get it from env
$HOME will be /home/USERNAME.
0
 
LVL 24

Accepted Solution

by:
shivsa earned 540 total points
ID: 9846801
#include <stdlib.h>

char *getenv(const char *NAME);
----------------------------------------------------

char *home = getenv( "HOME" );

char path[ MAXPATH];
strcpy( path, home );
strcat( path, "/your_directory/logfile" );
fopen( path, "w" );
0
 
LVL 24

Expert Comment

by:shivsa
ID: 9846808
or u can try this too.

char *name;
name = (char *)malloc(sizeof(char)*(PATH_MAX));
name = getcwd(name,PATH_MAX);

BTW: PATH_MAX is found in sys/types.h

also to leart more about getcwd use man getcwd.
0
 

Author Comment

by:nutterx
ID: 9846896
thanks shivsa
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question