Originally Posted by
jimblumberg
Please show your complete current code.
Also please show where you're allocating memory for all those pointers in your structure.
Jim
these are my codes, in full.
sorry that they are rather long.
Code:
#include <stdio.h>
#include <string.h>
struct Account
{
char* Account_ID;
char* Account_Type;
char* AccountOwner_FirstName;
char* AccountOwner_LastName;
float* Balance;
int* Phone_No;
int* AccountOwner_ID;
char* AccountOwner_Address;
char* AccountOwner_Email;
}acc1[100];
int main(void)
{
x://looping back if the user had quit from the program.
printf("Welcome to Global Bank Banking System.\n");
z://loop if the password or username entered is invalid;
//this is the authentication of verifying a bank staff login
printf("Please enter your user name: \n");
char UserName[] = "GBstaff";
scanf("%s", UserName);
printf("Please enter your password: \n");
char PassWord[] = "globalBANK";
scanf("%s", PassWord);
//if...else statement to test if the input is the correct username.
if (strcmp(UserName,"GBstaff") == 0)
{
if (strcmp(PassWord,"globalBANK") == 0){
printf("Welcome!\nWhat do you want to do?\n");
}
else
{
printf("The user name or password you entered is invalid.\nPlease try again.\n");
goto z;
}//end of if...else statement of password
}//end of only if statement of username
else
{
printf("The user name or password you entered is invalid.\nPlease try again.\n");
goto z;
}//the end of the else statement of the username.
y://loops from invalid input or after the completion of a task
printf("1 => Add a new bank account user\n2 => Delete an existing account user\n");
printf("3 => Search for an account\n4 => Search for the details of an account\n");
printf("5 => Update the information of an account\n6 => Account Balance Enquiry\n");
printf("7 => Withdraw certain amount of money\n8 => Transfer funds to another account user\n");
printf("9 => Bills Payment\n0 => Deposit money into an account\n");
//giving the structure an object name & becomes an arraylist.
struct Account acc1[100];
int count = 0;
//the selection of the functions listed above.
int selection;
scanf("%d",& selection);
switch(selection)
{
case 1://add a new account user
printf("Please enter a new Account ID:[max 10]\n");
char a[10];//Account ID
scanf("%s",a);
getchar();
acc1[count].Account_ID = a;
printf("Please enter the Account type:[max 25]\n");
char b[25];//Account Type
scanf("%s",b);
getchar();
acc1[count].Account_Type = b;
printf("Please enter the Owner's First name:[max 100]\n");
char c[100];//Owner Fname
scanf("%s",c);
getchar();
acc1[count].AccountOwner_FirstName = c;
printf("Please enter the Owner's Last Name:[max 100]\n");
char d[100];//Owner Lname
scanf("%s",d);
getchar();
acc1[count].AccountOwner_LastName = d;
printf("Please enter the current balance of this account:[min 1000.00]\n");
float e;//balance
scanf("%f",&e);
acc1[count].Balance = &e;
printf("Please enter the phone number of the Owner:\n");
int f;//phone
scanf("%d",&f);
getchar();
acc1[count].Phone_No = &f;
printf("Please enter a new Owner ID for this new account:[max 11]\n");
int g;//account owner ID
scanf("%d",&g);
getchar();
acc1[count].AccountOwner_ID = &g;
printf("Please enter the Home Address of the Owner:[max 1000]\n");
char h[1000];//address
scanf("%s",h);
getchar();
acc1[count].AccountOwner_Address = h;
printf("Please enter the email address of the Owner:[max 50]\n");
char i[50];//email address
scanf("%s",i);
getchar();
acc1[count].AccountOwner_Email = i;
printf("The new account has been successfully added into the database.\n");
break;
case 2://delete existing account user
printf("Please enter the account ID which you wish to delete.\n");
char* accID;
scanf("%s",accID);
int no;
for(no=0;no<100;no++)
{
if(strcmp(accID,acc1[no].Account_ID)==0)
{
acc1[no].Account_ID = "";
acc1[no].Account_Type = "";
acc1[no].AccountOwner_FirstName = "";
acc1[no].AccountOwner_LastName = "";
acc1[no].Balance = 0;
acc1[no].Phone_No = 0;
acc1[no].AccountOwner_Address = "";
acc1[no].AccountOwner_Email = "";
}//end if searching is successful
else {
printf("The Account ID you entered does not exist in the system.\n");
printf("Returning to the main menu.\n");
sleep(5);
goto y;
}//end of else statement when the searching failed.
}//end of the for loop for the searching.
break;
case 3://search account by account ID
printf("Please enter the Account ID:");
char* aID;
scanf("%s", *(aID));
int num;
for (num=0;num<100;num++)
{
if(strcmp(aID,acc1[num].Account_ID)==0)
{
printf("%s",acc1[num].Account_ID);
printf("%s",acc1[num].Account_Type);
printf("%s",acc1[num].AccountOwner_FirstName);
printf("%s",acc1[num].AccountOwner_LastName);
printf("%f",acc1[num].Balance);
printf("%d",acc1[num].Phone_No);
printf("%s",acc1[num].AccountOwner_Address);
printf("%s",acc1[num].AccountOwner_Email);
}//end of the if statement
else {
printf("This Account ID does not exist in the System.");
}//end of the for loop
break;
default:
printf("Invalid input, please enter again.\n");
goto y;
break;
}//end of switch
return 0;
}//end of the main class.