这是我在 c 中的代码
add_new_account 内部使用的是 scanf。
当我在 main 函数中打印它时,它会输出一个我键入的不同值。
有人可以帮我解决这个问题吗?
感谢您的帮助
struct account
{
char* F_name;
char* L_name;
int IC_No;
char* address;
char* e_address;
int c_number;
};
void add_new_account(struct account A[]){
int y=0;
char First_name[20],Last_name[20],addres[20],email[20];
int IC,number;
struct account add_account;
printf("First name :");
scanf("%s",First_name);
add_account.F_name=First_name;
printf("Last name :");
scanf("%s",Last_name);
add_account.L_name = Last_name;
printf("IC No. :");
scanf("%d",&IC);
add_account.IC_No = IC;
printf("Address :");
scanf("%s",addres);
add_account.address = addres;
printf("Email address :");
scanf("%s",email);
add_account.e_address = email;
printf("Contact number:");
scanf("%d",&number);
add_account.c_number = number;
A[y] = add_account;
}
int main(){
struct account A[20];
int y=0;
login();
add_new_account(&A);
printf("First name :");
printf("%c\n",A[y].F_name);
printf("Last name :");
printf("%s\n",A[y].L_name);
printf("IC No. :");
printf("%d\n",A[y].IC_No);
printf("Address :");
printf("%s\n",A[y].address);
printf("Email address :");
printf("%s\n",A[y].e_address);
printf("Contact number:");
printf("%d\n",A[y].c_number);
scanf("%d",&y);
return 0;
}