How do I get the user name of the current user?

后端 未结 6 1534
醉梦人生
醉梦人生 2021-01-14 20:05

I want to access the user name in the Windows using C programming and use that name to create the path to the particular file like \"c:\\users\\john\\Roaming.....and so on\"

6条回答
  •  庸人自扰
    2021-01-14 20:43

    #include  
    
    int main(void)
    {
        printf("%s\n", getenv("USERPROFILE"));  // Print user's home directory.
        return 0;
    }
    

    To get the user name instead of the home path replace USERPROFILE with USERNAME.

提交回复
热议问题