私がやろうとしているのは、管理者のユーザー名とパスワードを保存して、ユーザーが入力したものと保存されているものを比較できるようにすることですが、それを保存してポインターを使用する方法がわかりません。 strcpyを使用していますが、今は混乱しています...申し訳ありませんが、私が助けを必要としていることが説明されていることを願っています
#include <stdio.h>
#include <stdlib.h>
struct profile
{
char First[15];
char Last[15];
char Pwd[10];
char UserName[10];
};
void main_menu(struct profile user[]);
void admin_signIn(struct profile user[]);
void userSignUp(struct profile user[]);
void userSignOn(struct profile user[]);
void quit(struct profile user[]);
void admin_menu(struct profile user[]);
int main(int argc, char *argv[])
{
struct profile user[100];
struct profile *puser;
puser=&user[0];
puser.UserName[0] = "a";
//puser.Pwd = "password";
main_menu(user);
system("PAUSE");
return 0;
}
void main_menu(struct profile user[])
{
int choice = 0;
printf("User Menu\n");
printf(" \n");
printf("1 - Admin Sign In\n");
printf("2 - Sign Up\n");
printf("3 - Sign On\n");
printf("4 - Quit\n");
printf("Enter Choice:");
scanf("%d", &choice);
getchar();
if (choice == 1)
admin_signIn(user);
else
if (choice == 2)
userSignUp(user);
else
if(choice == 3)
userSignOn(user);
else
if(choice == 4)
quit(0);
}
void admin_signIn(struct profile *puser)
{
int i=0;
char buff_in[20];
//UserName="admin";
//puser->Pwd = "password";
//user[0].Last = " ";
//user[0].UserName="admin";
//user[0].Pwd="password";
//do
//{
printf("Enter admin user name:");
fgets(buff_in,10,stdin);
strcmp((puser+i)->UserName,buff_in);
printf("Enter admin password:");
fgets(buff_in,10,stdin);
strcmp((puser+i)->Pwd,buff_in);
i++;
fflush(stdin);
//printf("the user name is %s:", user[0].UserName);
//if(user[i].UserName==user[0].UserName && user[i].Pwd ==user[0].Pwd)
admin_menu(user);
else
printf("try again");
// }while(i<2);
}
void userSignUp(struct profile user[])
{
int i=0;
do
{
printf("Enter user name that you would like to use:\n");
gets(user[i].UserName);
//printf("enter user password:");
//gets(user[i].Pwd);
i++;
}while(i<2);
}
void userSignOn(struct profile user[])
{
printf("you are in the user sign on menu\n");
}
void quit(struct profile user[])
{
printf("the is the quit function\n");
}
void admin_menu(struct profile user[])
{
printf("you are in the admin menu\n");
}