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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -