linux编程精髓 源代码

源代码在线查看: ch06-groupinfo.c

软件大小: 39 K
上传用户: afaslgo
关键词: linux 编程 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				/* ch06-groupinfo.c --- Demonstrate getgrent() and struct group */								#include 				#include 				#include 								extern void print_group(const struct group *gr);								/* main --- print group lines for user named in argv[1] */								int				main(int argc, char **argv)				{					struct group *gr;					int i;									if (argc != 2) {						fprintf(stderr, "usage: %s user\n", argv[0]);						exit(1);					}									while ((gr = getgrent()) != NULL)						for (i = 0; gr->gr_mem[i] != NULL; i++)							if (strcmp(gr->gr_mem[i], argv[1]) == 0)								print_group(gr);									endgrent();									exit(0);				}								/* print_group --- print a group record */								void				print_group(const struct group *gr)				{					int i;									printf("%s:%s:%ld:", gr->gr_name, gr->gr_passwd, (long) gr->gr_gid);									for (i = 0; gr->gr_mem[i] != NULL; i++) {						printf("%s", gr->gr_mem[i]);						if (gr->gr_mem[i+1] != NULL)							putchar(',');					}									putchar('\n');				}							

相关资源