c - getenv returns null when asked for the username? -
i want username using stdlib
functio getenv ()
however null
here code have written:
#include<stdio.h> #include<stdlib.h> main() { char *hai; printf("the current user name is\n"); hai="user"; printf("%s\n",getenv(hai)); exit(0); }
does value getenv ()
returns depends on machine using compile code, , why value returned null
?
on windows, you'll need use getenv("username")
. user
/username
environment variable not standardized, , won't find environment variable named user
on windows unless set yourself.
Comments
Post a Comment