Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
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

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 On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Mac App Store ditched the usernames? Snookerman Mac Applications and Mac App Store 1 Apr 18, 2011 08:24 AM
Retrieving data in busted Touch wibbles iPod touch 1 Nov 23, 2009 01:05 PM
iphoto- can't retrieve photos in album-may have lost photos of daughter's birth! j9dons Mac Basics and Help 3 Jul 2, 2009 11:55 AM
Microsoft to remove support for @ usernames in http urls MacBytes MacBytes.com News Discussion 10 Jan 29, 2004 01:36 AM
Interface Prefs Lost While Changing Username in Root- Help! Arielle General Mac Discussion 3 Oct 9, 2003 10:33 AM


All times are GMT -5. The time now is 10:49 PM.

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

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