954,479 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

"[computername] says, 'Hello [username].'" with getenv()

0
By Ivan C on May 28th, 2009 5:53 am

Cheap, dirty code for Windows and *nix.

#include <stdio.h>
#include <stdlib.h>

#ifdef WIN32
  #define USER "USERNAME"
  #define HOST "COMPUTERNAME"
#elif defined __unix__
  #define USER "USER"
  #define HOST "HOST"
#else
  #error Sorry don't know the environment variable(of the target platform).
#endif

int main()
{
    printf("%s says, \"Hello %s.\"\n", getenv(HOST), getenv(USER));

    getchar();
    return(0);
}

This is a good example :) 5 stars!

athlon32
Junior Poster in Training
97 posts since Jan 2009
Reputation Points: 67
Solved Threads: 16
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You