欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當前位置:主頁 > 軟件編程 > C語言 >

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

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊: 次

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

上一篇:C語言中正切的相關(guān)函數(shù)總結(jié)

欄    目:C語言

下一篇:C語言判斷字符是否為可打印字符的方法

本文標題:C語言中fgetgrent()函數(shù)和fgetpwent()函數(shù)的用法對比

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/2832.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有