看了网友给的留言,原来得到当前用户名可以不是那么麻烦,修改一下,感谢网友yxx2008
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
int main()
{
uid_t userid;
struct passwd* pwd;
userid=getuid();
printf("userid is %d\n",userid);
pwd=getpwuid(userid);
printf("username is %s\nuserdir i %s\n",pwd->pw_name,pwd->pw_dir);
}
本文地址:http://com.8s8s.com/it/it27205.htm