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

发表于:2007-06-08来源:作者:点击数: 标签:
#includestdio.h #includeunistd.h #includesys/types.h #includepwd.h #includegrp.h intmain() { structpasswd*pwd=getpwuid(getuid()) structgroup*grp=getgrgid(getgid()) printf(name:%sgroup:%s\n,pwd-pw_name,grp-gr_name) return0 } sdccf 回复于:2

#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: %s\n", pwd->pw_name, grp->gr_name);
return 0;
}


 sdclearcase/" target="_blank" >ccf 回复于:2002-11-18 22:47:05
不错。

 mjc 回复于:2002-11-25 21:28:01
在sco下怎么不能编译!

 lcz88990200 回复于:2002-11-25 21:54:22
不会,一定是你没装开发系统

 wkl 回复于:2002-11-25 22:56:24
不错,这种小程序在编程中有很多用处!

 wellcome 回复于:2002-11-25 22:58:54
grp->gr_name 中   ->  是什么意思?

 mrhxn 回复于:2002-11-25 23:05:59
CC

 wellcome 回复于:2002-11-25 23:19:26
struct passwd *pwd = getpwuid(getuid());
谁能解是这行是什么意思? struct 是什么? 下面的->表示什么?


 lcz88990200 回复于:2002-11-25 23:48:18
看一看c语言编程基础

 wellcome 回复于:2002-11-25 23:50:04
能简要说一下吗?

 fanfan0737 回复于:2002-11-26 11:30:58
struct 是定义结构变量;
->     是指定结构变量里的成员(变量为结构指针变量)。

原文转自:http://www.ltesting.net