hello all, I have been given the task of creating a passwd program that uses the 'struct passwd' structure, in order to 1) read to first ten values of /etc/passwd file and display the userID and the userName. 2) Also once this is done, modify the program, so that it will store the first ten entry's from the password file into an array of structures. 3)print out the usernames and UID's this time using the array.

I have overcome the first part of the question (1) by using this:
Code:
 #include<stdio.h>
#include<pwd.h>   
main()
{
int i;	
struct passwd *pwd;
 setpwent(); 
	
for(i=0;i<10;i++) 		 
      {
	pwd=getpwent();
        printf("%s %d \n", (*pwd).pw_name,(*pwd).pw_uid); 
      }
endpwent();	
}
}
For part two, do need to declare another structure before main, with a character pointer for the username value and an int for the UID. like so:

Code:
typedef struct store
char *ptr_string;
int x;
} point;
Or do i have to use the struct passwd *ptr strucutre somehow? Need help on how to store the UID and Username into an array of structures please.