Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 29, 2009, 01:49 PM   #1
GenghisKhan
macrumors newbie
 
Join Date: Jan 2009
Retrieving Username in C++

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?
__________________
"Your voice says to go away, but your heart wants me to make you smile!" -- Neelix to Tuvok
GenghisKhan is offline   0 Reply With Quote
Old Jan 29, 2009, 01:54 PM   #2
GenghisKhan
Thread Starter
macrumors newbie
 
Join Date: Jan 2009
I looked it up in one of my linux books

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

Quote:
Originally Posted by GenghisKhan View Post
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?
__________________
"Your voice says to go away, but your heart wants me to make you smile!" -- Neelix to Tuvok
GenghisKhan is offline   0 Reply With Quote
Old Jan 29, 2009, 11:15 PM   #3
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
It might be better to use CSCopyUserName() from the CoreServices framework, but that's not cross-platform if you're going that route.
kainjow is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
need to mount NFS to home groupname username /home/$deptname/$username fishing4feeling OS X 10.8 Mountain Lion 0 Sep 5, 2013 10:23 AM
Retrieving password paieye OS X 10.8 Mountain Lion 0 Apr 22, 2013 01:41 AM
iPhone: Retrieving SHSH Blobs deviouz9k Jailbreaks and iOS Hacks 2 Nov 11, 2012 08:39 PM
Retrieving from iCloud Avaj iCloud and Apple Services 2 Sep 22, 2012 12:59 AM

Forum Jump

All times are GMT -5. The time now is 02:22 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC