ok i have incluced my structure as well as my pointer, here is what i am trying to figure out, i need to store up to 5 peoples profiles, but i do not know how to store these in my array while using a pointer
if i don’t have the pointer i can do it like this:
strcpy(user[0].UserName,”whatevername”);
strcpy(user[0].UserName,”whateverpwd”);
but how do i specify where in the array i want the info while using a point that points to my structure.. i hope this makes sense i don’t think i can explain it any better
struct profile
{
char First[15];
char Last[15];
char Pwd[10];
char UserName[10];
};
struct profile user[100];
struct profile *puser;
puser=&user[0];
void add_user(struct profile *puser)
{
int i = 0;
int j = 0;
int quit = 0;
char fname[30];
char lname[30];
char username[30];
char password[30];
do
{
printf("Enter the first name of the user:\n");
fgets((puser+i)->First,15, stdin);
printf("Enter the last name of the user:\n");
fgets((puser+i)->Last, 15, stdin);
printf("Enter the username:\n");
fgets((puser+i)->UserName, 30, stdin);
printf("Enter the password:\n");
fgets((puser+i)->Pwd, 30, stdin);
printf("the first name is: %s\n", (puser+i)->First);
printf("the last name is: %s\n", (puser+i)->Last);
printf("the user name is: %s\n", (puser+i)->UserName);
printf("the password name is: %s\n", (puser+i)->Pwd);
j++;
printf("enter 0 to exit 1 to continue:");
scanf("%d", &quit);
if(quit == 0)
printf("goodbye");
i++;
getchar();
}while(quit == 1);
}
Try this: