Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdbool.h>
- #define FILENAME "loginDetails.txt"
- char buffer[255];
- /* Create Account*/
- typedef struct{
- char *firstname;
- char *lastname;
- char *address;
- int mobileNum;
- int dateOfBirth[3];
- int accountNum;
- } userAccount;
- /* Login Account */
- typedef struct{
- char *userName;
- char *password;
- } Login;
- int mainMenu(void);
- bool login(void);
- void createAccount(void);
- void changeUserDets(userAccount *userDetails);
- float deposit(int balance);
- float withdraw(int balance);
- void viewCustomerBankInfo(userAccount *account);
- int editCustomerBankInfo(userAccount *customDetails);
- int delCustomerBankInfo(userAccount *customDetails);
- int main(void){
- int choice;
- bool checkLoggedin;
- printf("---Bᴀɴᴋ Mᴀɴᴀɢᴇᴍᴇɴᴛ Sʏsᴛᴇᴍ---\n");
- choice = mainMenu();
- do{
- switch(choice){
- case 1:
- checkLoggedin = login();
- if(checkLoggedin == true){
- choice = mainMenu();
- break;
- }else{ printf("Incorrect Username/Password!\n"); }
- break;
- case 2:
- createAccount();
- choice = mainMenu();
- break;
- default:
- exit(0);
- break;
- }
- }while(choice != 3);
- return 0;
- }
- int mainMenu(){
- char userChoice[10];
- printf("1 - Login\n");
- printf("2 - Create Account\n");
- printf("3 - Exit\n");
- printf("Enter a option\n");
- fgets(userChoice, 10, stdin);
- int choice = atoi(userChoice);
- if(choice == 1){ return choice; }
- else if(choice == 2){ return choice;}
- else{ choice;}
- }
- //Get the login details and store in a file.
- bool login(){
- FILE *loginDetails;
- char userNameFile[100];
- char passwordFile[100];
- loginDetails = fopen("loginDetails.txt", "r");
- if(!loginDetails){
- perror(FILENAME);
- return EXIT_FAILURE;
- }
- Login *loginAccount = malloc(sizeof(*loginAccount));
- loginAccount->userName = malloc(sizeof(*loginAccount->userName));
- loginAccount->password = malloc(sizeof(*loginAccount->password));
- printf("Enter in UserName: ");
- fgets(buffer, sizeof(buffer), stdin);
- sscanf(buffer, "%s", loginAccount->userName);
- printf("Enter in PassWord: ");
- fgets(buffer, sizeof(buffer), stdin);
- sscanf(buffer, "%s", loginAccount->password);
- //Check to see if the credntials are correct.
- while(!feof(loginDetails)){
- fscanf(loginDetails, "%s %s",userNameFile, passwordFile);
- if((strcmp(userNameFile, loginAccount->userName)) == 0 && (strcmp(passwordFile, loginAccount->password)) == 0){
- printf("Thanks For Banking with Us!\n");
- return true;
- break;
- }
- }
- free(loginAccount);
- free(loginAccount->userName);
- free(loginAccount->password);
- return false;
- }
- //User account creation stored on a file.
- void createAccount(){
- //Opening file for writing.
- FILE *createDetails;
- createDetails = fopen("createDetails.txt", "w");
- //Check if fopen() failed.
- if(!createDetails){
- perror("createDetails.txt");
- return;
- }
- userAccount *createUser = malloc(sizeof(*createUser));
- Login *loginDetails = malloc(sizeof(*loginDetails));
- printf("--Account Details--\n");
- printf("Enter in FirstName: ");
- createUser->firstname = malloc(sizeof(*createUser->firstname));
- fgets(buffer, sizeof(buffer), stdin);
- sscanf(buffer, "%s", createUser->firstname);
- printf("Enter in LastName: ");
- createUser->lastname = malloc(sizeof(*createUser->lastname));
- fgets(buffer ,sizeof(buffer), stdin);
- sscanf(buffer, "%s", createUser->lastname);
- //Add firstname and lastname to file.
- fprintf(createDetails, "%s %s", createUser->firstname, createUser->lastname);
- fflush(createDetails);
- free(createUser->firstname);
- free(createUser->lastname);
- printf("Enter in Address: ");
- createUser->address = malloc(sizeof(*createUser->address));
- fgets(buffer, sizeof(buffer), stdin);
- sscanf(buffer, "%s", createUser->address);
- printf("Enter in Mobile Number: ");
- createUser->mobileNum = malloc(sizeof(*createUser->mobileNum));
- fgets(buffer, sizeof(buffer), stdin);
- sscanf(buffer, "%s", createUser->mobileNum);
- //Add the address and mobile number
- fprintf(createDetails, "%s %d", createUser->address, createUser->mobileNum);
- fflush(createDetails);
- free(createUser->address);
- free(createUser->mobileNum);
- //Add the date of birth and account number.
- printf("Enter Date Of Birth: ");
- createUser->dateOfBirth = malloc(sizeof(*createUser->dateOfBirth));
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement