User domain

Sep 21, 2010 at 2:55pm
I'm trying to get the user domain as a function, but every time I call it, it display random characters instead of the user domain name. If I put everything as in main, it works perfectly, but I'm trying to make it a function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;


string GetDomain()
{
  char * DNSDomain;
  DNSDomain = getenv ("USERDNSDOMAIN");
  return 0;
}

int main ()
{
    printf ("The domain name is: %s",GetDomain);
}
Last edited on Sep 21, 2010 at 2:56pm
Sep 21, 2010 at 3:24pm
On line 12, GetDomain() returns 0.
Sep 21, 2010 at 3:28pm
GetDomain returns 0 instead of DNSDomain.
Here's the corrected code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;


string GetDomain()
{
  char * DNSDomain;
  DNSDomain = getenv ("UUSERDNSDOMAIN");
  return DNSDomain;
}

int main ()
{
     cout <<"The domain name is: "<<GetDomain()<<endl; // you can also use printf if you want
    
}


EDIT: too slow.
also, in your code you don't call GetDomain function correctly (you forgot () brrackets )
Last edited on Sep 21, 2010 at 3:32pm
Sep 21, 2010 at 5:58pm
Thank you, I knew it some thing simple I did wrong. Thanks again all...
Topic archived. No new replies allowed.