Access shell-variabels.

How can i find  out the name of the user running my c program in c??
marcooAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mmessuriConnect With a Mentor Commented:
marcoo:

Give this a try:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main(void)
{
  printf("You are logged in as: %s", getlogin() );

  return(0);
}

Note:

  The getlogin function returns the login name associated with the current user.
0
 
marcooAuthor Commented:
sorry in Linux!
0
 
marcooAuthor Commented:
Is it possible to manage it with getenv()??
0
 
mmessuriCommented:
marcoo:

Off the top of my head, no.  However you could also use:

cuserid()
0
All Courses

From novice to tech pro — start learning today.