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>
usingnamespace std;
string GetDomain()
{
char * DNSDomain;
DNSDomain = getenv ("USERDNSDOMAIN");
return 0;
}
int main ()
{
printf ("The domain name is: %s",GetDomain);
}
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>
usingnamespace 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
}