电脑技术学习

编程实(c++/c)现获得当前用户名和组名的源程序

dn001


#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>

int main()
{
struct passwd *pwd = getpwuid(getuid());
struct group *grp = getgrgid(getgid());

printf("name: %s group: %sn", pwd->pw_name, grp->gr_name);
return 0;
}


标签: 编程