#include <stdio.h>
#include <pwd.h>
#include <grp.h>

main()
{
	int i, uid, gid;
	struct *pbuf, *getpwuid();
	struct *gbuf, *getgrgid();

	/*
	 * Get his user id and group id.
	 */
	uid = getuid();
	gid = getgid();

	/*
	 * Get the password and group file entries.  Note 
	 * that we don't have to open the file, the routines
	 * do that for us.
	 */
	if ((pbuf = getpwuid(uid)) == NULL) {
		printf("No such user id \- %d\en", uid);
		exit(1);
	}

	if ((gbuf = getgrgid(gid)) == NULL) {
		printf("No such group id \- %d\en", gid);
		exit(1);
	}

	/*
	 * Print out the information.  Note that since
	 * pbuf and gbuf are pointers to structures, we
	 * reference their elements with '\->' and not 
	 * '.'
	 */
	printf("User id: %d\en", uid);
	printf("Group id: %d\en", gid);
	printf("Login name: %s\en", pbuf\->pw\(ulname);
	printf("Group name: %s\en", gbuf\->gr\(ulname);
	printf("Full name: %s\en", pbuf\->pw\(ulgecos);
	printf("Members of group:\en");

	for (i=0; gbuf\->gr\(ulmem[i] != NULL; i++)
		printf("\et%s\en", gbuf\->gr\(ulmem[i]);

	printf("Home directory: %s\en", pbuf\->pw\(uldir);
}
