Home
 
 
Search:  
C C++ Perl PHP Python HTML ShellScripts
 
 
  Coding Books
  Tutorials
  Search Code
  Browse Code
  Link to Us
  Site News
  Contact Metalshell
 
 
 
  Submit Code   Statistics
 



Linux Programmer's Reference    (ISBN: 0072123559)


 

 List Price: $19.99
 Our Price: $19.99
 Used Price: $3.87

 Release Date: 10 December, 1999
 Manufacturer: McGraw-Hill Osborne Media (Paperback)
 Sales Rank: 165,538

 Author: Richard Petersen









More Info

 List Users 2003-05-01 22:05:53
 
Category: source:c:linux
Description: Simple program to print all of the known users from the /etc/passwd file.
Platform: unix
Author: pipas
Viewed: 2810
Rating: 3.8/5 (12 votes)
If you have any questions about this piece of code or still need help, try posting your question on the forum.

 

Printable Version
getpwent.c
/*
 * 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*/
Rate this code:
(Not Helpful)  (Very Helpful) 

 
 
   Developer.*  
   Blue Parrots  
   Technipal  
   Defy Magazine  
   Code Project  
   Prog. Heaven  


Got Money?