## getgrent ##
從組文件中取得賬號的數據
### 相關函數 ###
setgrent,endgrent
### 表頭文件 ###
```
#include<grp.h>
#include <sys/types.h>
```
### 定義函數 ###
```
struct group *getgrent(void);
```
### 函數說明 ###
getgrent()用來從組文件(/etc/group)中讀取一項組數據,該數據以group 結構返回。第一次調用時會取得第一項組數據,之后每調用一次就會返回下一項數據,直到已無任何數據時返回NULL。
```
struct group{
char *gr_name; /*組名稱*/
char *gr_passwd; /* 組密碼*/
gid_t gr_gid; /*組識別碼*/
char **gr_mem; /*組成員賬號*/
}
```
### 返回值 ###
返回group結構數據,如果返回NULL則表示已無數據,或有錯誤發生。
### 附加說明 ###
getgrent()在第一次調用時會打開組文件,讀取數據完畢后可使用endgrent()來關閉該組文件。
### 錯誤代碼 ###
ENOMEM 內存不足,無法配置group結構。
### 范例 ###
```
#include<grp.h>
#include<sys/types.h>
main()
{
struct group *data;
int i;
while((data= getgrent())!=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”);
}
endgrent();
}
```
### 執行 ###
```
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
```
- 字符測試篇
- isalnum
- isalpha
- isascii
- iscntrl
- isdigit
- isgraphis
- islower
- isprint
- isspace
- ispunct
- isupper
- isxdigit
- 字符串轉換篇
- atof
- atoi
- atol
- gcvt
- strtod
- strtol
- strtoul
- toascii
- tolower
- toupper
- 內存控制篇
- calloc
- free
- getpagesize
- malloc
- mmap
- munmap
- 日期時間篇
- asctime
- ctime
- gettimeofday
- gmtime
- localtime
- mktime
- settimeofday
- time
- 內存及字符串操作篇
- bcmp
- bcopy
- bzero
- index
- memccpy
- memchr
- memcmp
- memcpy
- memmove
- memset
- rindex
- strcasecmp
- strcat
- strchr
- strcmp
- strcoll
- strcpy
- strcspn
- strdup
- strlen
- strncasecmp
- strncat
- strncpy
- strpbrk
- strrchr
- strspn
- strstr
- strtok
- 常用數學函數篇
- abs
- acos
- asin
- atan
- atan2
- ceil
- cos
- cosh
- exp
- frexp
- ldexp
- log
- log10
- pow
- sin
- sinh
- sqrt
- tan
- tanh
- 用戶組篇
- endgrent
- endpwent
- endutent
- fgetgrent
- fgetpwent
- getegid
- geteuid
- getgid
- getgrent
- getgrgid
- getgrnam
- getgroups
- getpw
- getpwent
- getpwnam
- getpwuid
- getuid
- getutent
- getutid
- getutline
- initgroups
- pututline
- seteuid
- setfsgid
- setfsuid
- setgid
- setgrent
- setgroups
- setpwent
- setregid
- setreuid
- setuid
- setutent
- utmpname
- 數據結構及算法篇
- crypt
- bsearch
- lfind
- lsearch
- qsort
- rand
- srand
- 文件操作篇
- close
- creat
- dup
- dup2
- fcntl
- flock
- fsync
- lseek
- mkstemp
- open
- read
- sync
- write
- 文件內容操作篇
- clearerr
- fclose
- fdopen
- feof
- fflush
- fgetc
- fgets
- fileno
- fopen
- fputc
- fputs
- fread
- freopen
- fseek
- ftell
- fwrite
- getc
- getchar
- gets
- mktemp
- putc
- putchar
- rewind
- setbuf
- setbuffer
- setlinebuf
- setvbuf
- ungetc
- 進程操作篇
- atexit
- execl
- execlp
- execv
- execve
- execvp
- exit
- _exit
- vfork
- getpgid
- getpgrp
- getpid
- getppid
- getpriority
- nice
- on_exit
- setpgid
- setpgrp
- setpriority
- system
- wait
- waitpid
- 格式化輸入輸出篇
- fprintf
- fscanf
- printf
- scanf
- sprintf
- sscanf
- vfprintf
- vfscanf
- vprintf
- vscanf
- vsprintf
- vsscanf
- 文件權限控制篇
- access
- alphasort
- chdir
- chmod
- chown
- chroot
- closedir
- fchdir
- fchmod
- fchown
- fstat
- ftruncate
- getcwd
- link
- lstat
- opendir
- readdir
- readlink
- remove
- rename
- rewinddir
- seekdir
- stat
- symlink
- telldir
- truncate
- umask
- unlink
- utime
- utimes
- 信號處理篇
- alarm
- kill
- pause
- sigaction
- sigaddset
- sigdelset
- sigemptyset
- sigfillset
- sigismember
- signal
- sigpending
- sigprocmask
- sleep
- ferror
- perror
- strerror
- mkfifo
- pclose
- pipe
- popen
- 接口處理篇
- accept
- bind
- connect
- endprotoent
- endservent
- getsockopt
- htonl
- htons
- inet_addr
- inet_aton
- inet_ntoa
- listen
- ntohl
- ntohs
- recv
- recvfrom
- recvmsg
- send
- sendmsg
- sendto
- setprotoent
- setservent
- setsockopt
- shutdown
- socket
- 環境變量篇
- getenv
- putenv
- setenv
- 終端控制篇
- getopt
- isatty
- select
- ttyname