List Users
2003-05-01 22:05:53
Category: c:linux
Description: Simple program to print all of the known users from the /etc/passwd file.
Author: pipas
Viewed: 2974
Rating: (12 votes)


/*
 * Example program by pipas@linux.pte.hu
 * This program lists all the users from
 * the user database (/etc/passwd).
 *
 * http://www.metalshell.com/
 */
 
#include <stdio.h>
#include <pwd.h>
#include <sys/types.h>
 
main() {
  struct passwd *user;
 
  /* open the user database */
  setpwent();
 
  /* read the user data one by one
     and print their names to stdout */
  while( (user=getpwent())!=NULL )
    printf("%s\n", user->pw_name);
 
  /* close the database */
  endpwent();
}  /*main*/