国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C > 正文

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

2020-01-26 14:56:30
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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

頭文件:

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

定義函數(shù):

struct group * getgrent(FILE * stream);

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

返回值:返回 group 結(jié)構(gòu)數(shù)據(jù), 如果返回NULL 則表示已無(wú)數(shù)據(jù), 或有錯(cuò)誤發(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, daemondaemon:x:2:root, bin, daemonsys:x:3:root, bin, admadm:x:4:root, adm, daemontty:x:5disk:x:6:rootlp:x:7:daemon, lpmem:x:8kmem:x:9wheel:x:10:rootmail:x:12:mailnews:x:13:newsuucp:x:14:uucpman:x:15games:x:20gopher:x:30dip:x:40:ftp:x:50nobody:x:99:

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

頭文件:

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

定義函數(shù):

struct passwd * fgetpwent(FILE * stream);

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

返回值:返回 passwd 結(jié)構(gòu)數(shù)據(jù), 如果返回NULL 則表示已無(wú)數(shù)據(jù), 或有錯(cuò)誤發(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/bashbin: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/syncshutdown:6:0:shutdown:/sbin:/sbin/shutdownhalt:7:0:halt:/sbin:/sbin/haltmail:8:12:mail:/var/spool/mail:news:9:13:news:var/spool/newsuucp: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/falsegdm:42:42:/home/gdm:/bin/bashkids:500:500: : /home/kids:/bin/bash

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 株洲市| 山丹县| 濉溪县| 涟水县| 句容市| 浦县| 永和县| 襄城县| 通山县| 云霄县| 武夷山市| 肇州县| 洛南县| 湖北省| 竹北市| 新乡县| 时尚| 苍溪县| 崇文区| 九台市| 沙洋县| 新巴尔虎左旗| 秀山| 虎林市| 巨鹿县| 绩溪县| 安吉县| 霞浦县| 元江| 礼泉县| 古蔺县| 陆川县| 通道| 四会市| 丰台区| 丽水市| 增城市| 莱芜市| 威远县| 德安县| 泊头市|