看了网友给的留言,原来得到当前用户名可以不是那么麻烦,修改一下,感谢网友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);
}