最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C語言中fgetgrent()函數(shù)和fgetpwent()函數(shù)的用法對比

 更新時間:2015年08月28日 11:34:56   投稿:goldensun  
這篇文章主要介紹了C語言中fgetgrent()函數(shù)和fgetpwent()函數(shù)的用法對比,分別用于讀取組格式函數(shù)和讀取密碼格式,需要的朋友可以參考下

C語言fgetgrent()函數(shù):讀取組格式函數(shù)

頭文件:

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

定義函數(shù):

struct group * getgrent(FILE * stream);

函數(shù)說明:fgetgrent()會從參數(shù)stream 指定的文件讀取一行數(shù)據(jù), 然后以group 結(jié)構(gòu)將該數(shù)據(jù)返回. 參數(shù)stream 所指定的文件必須和、etc/group 相同的格式. group 結(jié)構(gòu)定義請參考getgrent().

返回值:返回 group 結(jié)構(gòu)數(shù)據(jù), 如果返回NULL 則表示已無數(shù)據(jù), 或有錯誤發(fā)生.

范例

#include <grp.h>
#include <sys/types.h>
#include <stdio.h>
main()
{
  struct group *data;
  FILE *stream;
  int i;
  stream = fopen("/etc/group", "r");
  while((data = fgetgrent(stream)) != 0)
  {
    i = 0;
    printf("%s :%s:%d :", data->gr_name, data->gr_passwd, data->gr_gid);
    while(data->gr_mem[i])
      printf("%s, ", data->gr_mem[i++]);
    printf("\n");
  }
  fclose(stream);
}

執(zhí)行:

root:x:0:root,
bin:x:1:root, bin, daemon
daemon:x:2:root, bin, daemon
sys:x:3:root, bin, adm
adm:x:4:root, adm, daemon
tty:x:5
disk:x:6:root
lp:x:7:daemon, lp
mem:x:8
kmem:x:9
wheel:x:10:root
mail:x:12:mail
news:x:13:news
uucp:x:14:uucp
man:x:15
games:x:20
gopher:x:30
dip:x:40:
ftp:x:50
nobody:x:99:

C語言fgetpwent()函數(shù):讀取密碼格式

頭文件:

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

定義函數(shù):

struct passwd * fgetpwent(FILE * stream);

函數(shù)說明:fgetpwent()會從參數(shù)stream 指定的文件讀取一行數(shù)據(jù), 然后以passwd 結(jié)構(gòu)將該數(shù)據(jù)返回. 參數(shù)stream 所指定的文件必須和/etc/passwd 相同的格式. passwd 結(jié)構(gòu)定義請參考getpwent().

返回值:返回 passwd 結(jié)構(gòu)數(shù)據(jù), 如果返回NULL 則表示已無數(shù)據(jù), 或有錯誤發(fā)生.

范例

#include <pwd.h>
#include <sys/types.h>
main()
{
  struct passwd *user;
  FILE *stream;
  stream = fopen("/etc/passwd", "r");
  while((user = fgetpwent(stream)) != 0)
  {
    printf("%s:%d:%d:%s:%s:%s\n", user->pw_name, user->pw_uid, user->pw_gid,
    user->pw_gecos, user->pw_dir, user->pw_shell);
  }
}

執(zhí)行:

root:0:0:root:/root:/bin/bash
bin:1:1:bin:/bin:
daemon:2:2:daemon:/sbin:
adm:3:4:adm:/var/adm:
lp:4:7:lp:/var/spool/lpd:
sync:5:0:sync:/sbin:/bin/sync
shutdown:6:0:shutdown:/sbin:/sbin/shutdown
halt:7:0:halt:/sbin:/sbin/halt
mail:8:12:mail:/var/spool/mail:
news:9:13:news:var/spool/news
uucp:10:14:uucp:/var/spool/uucp:
operator:11:0:operator :/root:
games:12:100:games:/usr/games:
gopher:13:30:gopher:/usr/lib/gopher-data:
ftp:14:50:FTP User:/home/ftp:
nobody:99:99:Nobody:/:
xfs:100:101:X Font Server: /etc/Xll/fs:/bin/false
gdm:42:42:/home/gdm:/bin/bash
kids:500:500: : /home/kids:/bin/bash

相關(guān)文章

最新評論

玉林市| 宕昌县| 蒲城县| 双辽市| 修水县| 红安县| 澄迈县| 福安市| 原平市| 和硕县| 新龙县| 东平县| 葫芦岛市| 惠安县| 龙泉市| 崇礼县| 伊宁市| 盐津县| 明星| 武功县| 邵东县| 介休市| 宜州市| 巴林左旗| 怀柔区| 株洲市| 遵化市| 蒙山县| 和龙市| 甘泉县| 杭州市| 巴中市| 宜兰市| 高州市| 张掖市| 宁津县| 建水县| 迭部县| 定襄县| 上杭县| 平乐县|