Print computer/system name

This is a discussion on Print computer/system name within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Salem Tough - it won't, nor can it ever work on both. Certainly, there's no standard way ...

  1. #16
    Registered User
    Join Date
    May 2005
    Posts
    54
    Quote Originally Posted by Salem
    Tough - it won't, nor can it ever work on both.

    Certainly, there's no standard way to find out.

    I suppose you could find some very common library somewhere, which might happen to tell you which machine you're on...
    I'll look into it. Thanks for your help though .
    -Zack

  2. #17
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by JizJizJiz
    It has to work on both .
    Why should it ?!? It's OS specific coding, therefore you won't find support for other OS rrather that Windows on a MS compiler...

    Code:
    #define WINSOURCE (defined(WIN32) || defined(WIN64))
    
    #if WINSOURCE
    #include<windows.h>
    #else
    #include<sys/utsname.h>
    #endif
    
    char *get_pcname(){
        static char buffer[256];
    #if WINSOURCE
        DWORD len = 256;
        GetComputerName(buffer, &len);
    #else
        struct utsname booh;
        memset(&booh,0,sizeof(booh));
        uname(&booh);
        int len = strlen(booh.nodename);
        memcpy(buffer,booh.nodename,len>255?255,len);
        buffer[255]=0;
    #endif
        return buffer;
    }

  3. #18
    Registered User
    Join Date
    May 2005
    Posts
    54
    Quote Originally Posted by xErath
    Why should it ?!? It's OS specific coding, therefore you won't find support for other OS rrather that Windows on a MS compiler...

    Code:
    #define WINSOURCE (defined(WIN32) || defined(WIN64))
    
    #if WINSOURCE
    #include<windows.h>
    #else
    #include<sys/utsname.h>
    #endif
    
    char *get_pcname(){
        static char buffer[256];
    #if WINSOURCE
        DWORD len = 256;
        GetComputerName(buffer, &len);
    #else
        struct utsname booh;
        memset(&booh,0,sizeof(booh));
        uname(&booh);
        int len = strlen(booh.nodename);
        memcpy(buffer,booh.nodename,len>255?255,len);
        buffer[255]=0;
    #endif
        return buffer;
    }
    Understood. I was a bit slow on Friday...doing lots of work at once . Sorry.
    -Zack

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. merging linked lists
    By scwizzo in forum C++ Programming
    Replies: 15
    Last Post: 09-14-2008, 06:07 PM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 01:13 AM
  3. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM
  4. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 09:13 PM
  5. Replies: 1
    Last Post: 07-31-2002, 12:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21