Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

GenghisKhan

macrumors newbie
Original poster
Jan 18, 2009
4
0
Hi there, I'm working on a small XCode project to get my C++ skills up to par again.

I need to retrieve the username to use with a path command in "int execpl(char *path, char *arg, ...)". Since this app is going to run on somebody else's Mac and I don't know his username, I need a smart way to retrieve it.

I could get it from the environment variable $USER but I don't know how to do this in C++.

Anyone?
 

GenghisKhan

macrumors newbie
Original poster
Jan 18, 2009
4
0
I looked it up in one of my linux books

You can use "stdlib.h" apparantly, to use char *getenv(const char *name);

Hi there, I'm working on a small XCode project to get my C++ skills up to par again.

I need to retrieve the username to use with a path command in "int execpl(char *path, char *arg, ...)". Since this app is going to run on somebody else's Mac and I don't know his username, I need a smart way to retrieve it.

I could get it from the environment variable $USER but I don't know how to do this in C++.

Anyone?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
It might be better to use CSCopyUserName() from the CoreServices framework, but that's not cross-platform if you're going that route.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.