/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
/* a sample program that prints all the groupname */
#include <stdio.h>
#include <grp.h>

int main() {
    struct group *pgroup;
    char schgroup[]="student";
    
    pgroup = getgrent();
    printf(" the group name is '%s' \n",pgroup->gr_name);
     
    setgrent();  // rewind  the file to reread the group
    pgroup = getgrnam(schgroup);
    printf(" the student group's group ID is '%d'.\n",pgroup->gr_gid);
    pgroup = getgrgid(pgroup->gr_gid);
    printf(" the name of the group which group ID is %d is '%-s'.\n",pgroup->gr_gid,pgroup->gr_name);
    endgrent();
}
