Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get A Username

Status
Not open for further replies.

programerrusuk

Programmer
Jan 28, 2005
55
GB
Is there a way to get a user's username and create it as a varible. I want to have it in a sprintf command so it will show me which user on mu network used it. Please help
 
There are a couple of ways to do this the easist is to use the enviroment variable USER... using getenv and setenv:

Function char * getenv (const char *name)
This function returns a string that is the value of the environment variable name. You must not modify this string. In some non-Unix systems not using the GNU library, it might be overwritten by subsequent calls to getenv (but not by any other library function). If the environment variable name is not defined, the value is a null pointer.

Function int putenv (const char *string)
The putenv function adds or removes definitions from the environment. If the string is of the form `name=value', the definition is added to the environment. Otherwise, the string is interpreted as the name of an environment variable, and any definition for this variable in the environment is removed.

The GNU library provides this function for compatibility with SVID; it may not be available in other systems.
from
This is cheap and dirty, but should not be used for granting access... as this is easy to fool. There are other methods, but I can't recall them at the moment.

[plug=shameless]
[/plug]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top