Thread: Need help Regarding Bank System Project!

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    4

    Need help Regarding Bank System Project!

    hi
    i need urgent help if somebody can do for it


    below is the code

    the problem is that my search function not working , it always show the last value correct but not the first and others

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    #include<stdlib.h>
    #include <ctype.h>                // used for toLower etc
    
    //-----------------------------------------------------------------------------------------------
    //--------------------------- Structure for Accounts holder --------------------------------------
    //-----------------------------------------------------------------------------------------------
    
    
    
    struct bank_management{
           char id[30];
           char acc_title[30];
           char searchaccount[15];
           char add_acc_holder[30];
           char curr_balance[30];
           char acc_op_date[30];
           char acc_type[30];
           char x[10];
           };
    
    
    //-------------------------------------------------------------------------------------------------
    //------------------------------- Prototype for Functions -----------------------------------------
    //-------------------------------------------------------------------------------------------------
    
    
    
    void create(struct bank_management *);             // This function will create a bank account
    void del(struct bank_management *);                // This function will delete the account
    void search(struct bank_management *);             // This function will search an exsisting account
    void deduct(struct bank_management *);             // This function will deduct amount from current balance
    void add(struct bank_management *);                // This function will add ammount to current balance account
    void edit(struct bank_management *);               // This function will edit an exsisting 
    void exit(struct bank_management *);               // This function will exit program
    void print(struct bank_management *);              // This function will print
    int checkNumber(char[], int);                      // checks for numbers    
    int checkLetters(char[]);                          // checks for letters/characters
    
        //------------------------------- Main Menu for the Program --------------------------------------------//
        //------------------------------------------------------------------------------------------------------//
        //------------------------------------------------------------------------------------------------------//
        //------------------------------------------------------------------------------------------------------//
        //------------------------------------------------------------------------------------------------------//
    
    
    int main(){
        system("color 03");
        
        int x;
        struct bank_management data;
        struct bank_management *dataptr;
        dataptr=&data;
        /*
        printf("\t  -----------------------------------------------\n");
        printf("\t  -----------------------------------------------\n");
        printf("\t  -----------------------------------------------\n");
        printf("\t   Comsats University of Sciences and Technology\n");
        printf("\t  -----------------------------------------------\n");
        printf("\t  --------------- Muhammad Azhar ----------------\n");
        printf("\t  --------------- CIIT/FA11-BCS-100 -------------\n");
        printf("\t  ------------------- BCS - IB ------------------\n");
        printf("\t  -----------------------------------------------\n");
        printf("\t  -----------------------------------------------\n");
        printf("\t  -----------------------------------------------\n\n\n\n\n       \t\t");
        
        
        */
        
        
        
        
        system("cls");
        
        
        
        
        
        
        printf("\t\t----------------------------------------------------\n");
        printf("\t\t--------------------- Main Menu --------------------\n");
        printf("\t\t----------------------------------------------------\n");
        printf("\n\n");
        printf("1. Create a New Account\n\n\n");
        printf("2. Delete an Account\n\n\n");
        printf("3. Search the details of an Account\n\n\n");
        printf("4. Deduct Ammount from the Account\n\n\n");
        printf("5. Add amount to the Account\n\n\n");
        printf("6. Edit the Details of Account\n\n\n");
        printf("7. Exit the Program\n\n");
        
       
        scanf(" %d", &x);
        
        switch(x)
        {
                 
                 // Case 1: --- for new account//
                 
                 case 1: 
                         create(&data);
                         break;
                 // Case 2: --- for deleting an account//
                     
                 case 2:
                         del(&data);
                         break;
                         
                 // Case 3: ---  Search an exsisting account//
                  
                 case 3: 
                      
                         search(&data);
                         break;
                         
                 // Case 4: --- Deduct amount from the account//
                                       
                 case 4:
                       
                         deduct(&data);
                         break;
                         
                 // Case 5: --- Add amount to the account//
                 
                 case 5:
                      
                         add(&data);
                         break;
                         
                         
                 // Case 6: --- Edit data of an exsisting account//
                 
                 case 6:
                      
                         edit(&data);
                         break;
        
                 // Case 7: --- Exit the Program//
        
                 
                 case 7:
                      
                         exit(&data);
                         break;
                         
                 // Default case that will till if value entered wrong!// 
                 
                 
                 
                 default:
                         
                         printf("Enter the Valid Entry Number Please\n\n");
                         system("pause");
                         main(); 
        
        }
        
        getche();
        return 0;
        
    }
    
    
    // Function where it will make account creation for bank system
    
        
    void create(struct bank_management *data)
    {
    
         system("cls");
         
         FILE *fdata;
         fdata=fopen("record_account.dat", "ab");  
         if (fdata== NULL)
         {
         puts("Unable to open the file");
         main();
         }  
    
         char next = 'Y';
        
        
        
        system("cls"); 
        
        while( (next == 'Y' ) || (next == 'y') )
        { 
               
        //fwrite( &data, sizeof (data), 1, fdata );       
        printf("\t   --------------------------------------------------------- \n");
        printf("\t    ------ Welcome to Account Creation System   ------ \n");
        printf("\t   --------------------------------------------------------- \n");
        printf("\n\n");
        printf("1. Enter an Account ID\n");
        fflush(stdin);
        scanf("%s", data->id);
        
        
           
           
        printf("2. Enter an Account Title\n");
        fflush(stdin);
        scanf("%s", data->acc_title);
        
        
      
        
        printf("3. Enter Address Account Holder\n");
        fflush(stdin);
        scanf("%s", data->add_acc_holder);
        printf("4. Enter Current Balance in Account\n");
        fflush(stdin);
        scanf("%s", data->curr_balance);
        
     
        
        printf("5. Enter Account Opening Date in this format ( MM/DD/YY)\n");
        fflush(stdin);
        scanf("%s", data->acc_op_date);    
        printf("6. Enter Account Type - Current or Savings:\n");
        fflush(stdin);
        scanf("%s", data->acc_type);
        
        
    
        fwrite( data, sizeof(*data), 1, fdata );
        
        printf( "\n\nDo you want to enter another account\n");
        next = getche();
           
        
        
        }
              
        
        fclose(fdata);
        main();
    
    }
        
        
        
    void del(struct bank_management *data)
    {
         system("cls");             
         
         char another;
         char ido[10];
         char x;
         FILE *ftemp, *fdata;
         
         
         fdata = fopen("record_account.dat", "rb+");
         if(fdata==NULL)
         {
                        printf("Unable to open the file");
                        
         }
         printf("\t\t------------------\n");
         printf("\t\t-Delete an Account-\n");
         printf("\t\t------------------\n");
         printf("\n ID \n TITLE \n ADDRESS \n CURRENT BALANCE \n ACCOUNT OPENING DATE \n ACCOUNT TYPE \n");
         printf("---------------------------------------------------------------------------");
         
                
         
         printf("\n\nEnter account No to Delete: ");
         fflush(stdin);
         gets(ido);
         
         ftemp = fopen("Temp.dat", "wb+");
         
         rewind(fdata);
         
        
         while(fread ( data, sizeof(*data), 1, fdata) )
         {
                     if(strcmp(ido, data->id)!=0 )
                     {
                                fseek(fdata, -sizeof(*data), SEEK_CUR);
                                fwrite( data, sizeof(*data), 1, ftemp);
                                printf("\n\t\tRecord Deleted Sucessfully!"); 
                    
                    
                     }             
         fclose(fdata);
         fclose(ftemp);
    
         remove("record_account.dat");
         rename("Temp.dat", "record_account.dat");
         
         
         fdata=fopen("record_account.dat","r+");
         
         fclose(fdata);
         
         
         system("cls");
         
         main();
         }
    
    }
    
    
    
    // This function will check wether the account exsist or not.
    //-----------------------------------------------------------
    //-------------------------------------------------------------
    //------------------------------------------------------------- //
    
    
    
    void search(struct bank_management *data)
    {
    
         system("cls");
         char searchaccount[15];
         int record = 0; 
         FILE *fdata;
         fdata = fopen("record_account.dat", "r+");
         if(fdata == NULL)
         {
                  printf("Unable to open the file");
                  
         }
         printf(" \t\t ---------------------- \n");
         printf(" \t\t --Searching Accounnt-- \n");
         printf(" \t\t ---------------------- \n"); 
         fflush(stdin);
         while( fread( data, sizeof (*data), 1, fdata) )
         {
                printf("\n ID =  %s\n Account Title =  %s\n Account Address = %s\n Current Balance =  %s\n Account Opening Date = %s\n Account Type = %s\n", data->id, data->acc_title, data->add_acc_holder, data->curr_balance, data->acc_op_date, data->acc_type);
                printf("\n-----------------------------------------------------------------------------------\n");
         }
         printf("Please Enter Account NO or Account Holder to Search his Details\n\n");
         gets(searchaccount);
         
         rewind(fdata);
         
         
         
         
         while( fread( &searchaccount, sizeof(*searchaccount), 1, fdata) )
         {
                if(strcmp(!searchaccount,data->id))
                {
                record = 1;
                
                printf("Record found");
                printf("\n ID =  %s\n Account Title =  %s\n Account Address = %s\n Current Balance =  %s\n Account Opening Date = %s\n Account Type = %s\n", data->id, data->acc_title, data->add_acc_holder, data->curr_balance, data->acc_op_date, data->acc_type);
                printf("\n-----------------------------------------------------------------------------------\n");
                system("pause");
                main();
         
                
                }     
         }       
         
                if(record==0)
                {
                             printf("\n\nRecord doesn't exsist\n\n\n") ;
                             
                             
                             system("pause");
                             
                             printf("Do you want to search again?(Y/N)\n\n");
                             
                             
                             main();
                             
                             
                             
                             
                             
                }
    
    
    }
    
    
    
    // This function will deduct amount from the current balance
    //-----------------------------------------------------------
    //-------------------------------------------------------------
    //------------------------------------------------------------- //
    
    
    
    
    
    
    void deduct(struct bank_management *data)
    {
         system("cls");
         
         char d[10];
         FILE *fdata;
         fdata=fopen("record_account.dat", "rb");
         if(fdata==NULL)
         {
         printf("Unable to open the file");
         }
         
         printf("\n\n --------------------------");
         printf("\n\n ----Withdraw Amount-------");
         printf("\n\n  --------------------------");
         printf("\n ID \n TITLE \n ADDRESS \n CURRENT BALANCE \n ACCOUNT OPENING DATE \n ACCOUNT TYPE \n");
         printf("---------------------------------------------------------------------------");
         
         
         while( fread ( data, sizeof(*data), 1, fdata) )
         {
    
                printf("\n ID =  %s\n Account Title =  %s\n Account Address = %s\n Current Balance =  %s\n Account Opening Date = %s\n Account Type = %s\n", data->id, data->acc_title, data->add_acc_holder, data->curr_balance, data->acc_op_date, data->acc_type);
                printf("\n-----------------------------------------------------------------------------------\n");
         
                       
         }            
         printf("\n\nEnter the Account ID: ");
         fflush(stdin);
         gets(d);
         rewind(fdata);
         
          while( fread ( data, sizeof(*data), 1, fdata) )
         {
             if(!strcmp(d, data->id))
             {
        
                 printf("Your current balance is : %s\n", data->curr_balance);
                 printf("Enter the amount you want to deduct or Withdraw from your Current Balance\n");
                 scanf("%s", data->x);  
                 if( (data->curr_balance >=0) ){
                     itoa((atoi(data->curr_balance) - atoi(data->x)), data->curr_balance, 10);
                     
                     
                     printf("Now Your balance = %s", data->curr_balance);
    
                     system("pause");
                     main();
                 }
                 else
                 {
                     printf("Sorry, You have money less than 0 in your current balance");
                 }
              }    
         }
         
    }
    
    
    
    
    
    
    // This function will add amount to the current balance
    //-----------------------------------------------------------
    //-------------------------------------------------------------
    //------------------------------------------------------------- //
    
    
    
    
    
    
    void add(struct bank_management *data)
    {
         system("cls");
         char n[10];
         
         FILE *fdata;
         
         fdata=fopen("record_account.dat", "rb");
         if(fdata==NULL)
         {
                printf("Unable to Open the file");
                
         }
         
         printf("\n\n-----------------------");
         printf("\n\n----Add Ammount--------");
         printf("\n\n-----------------------");
         printf("\n ID \n TITLE \n ADDRESS \n CURRENT BALANCE \n ACCOUNT OPENING DATE \n ACCOUNT TYPE \n");
         printf("---------------------------------------------------------------------------");
         
         
         while( fread ( data, sizeof(*data), 1, fdata) )
         {
    
                printf("\n ID =  %s\n Account Title =  %s\n Account Address = %s\n Current Balance =  %s\n Account Opening Date = %s\n Account Type = %s\n", data->id, data->acc_title, data->add_acc_holder, data->curr_balance, data->acc_op_date, data->acc_type);
                printf("\n-----------------------------------------------------------------------------------\n");
         
                       
         }
         
         printf("\n\nEnter the Account ID: ");
         scanf("%s", n);
         rewind(fdata);
         
         while( fread (data, sizeof(*data), 1, fdata) )
         {
                if(!strcmpi(n,data->id) )
                {
                                       
         
         printf("Your current balance is : %s\n", data->curr_balance);
         printf("Enter the amount you want to add in you Current Balance\n");
         scanf("%s", data->x);
         
         itoa((atoi(data->curr_balance) + atoi(data->x)), data->curr_balance, 10);
     
         printf("Now Your balance = %s", data->curr_balance);
         
         system("pause");
         main();
         
         }
         
         
         else
         {
             printf("You have entered the wrong account ID\n");
             printf("You will not able to write the Account ID again");
         }
         }
    }
    
    
    
    
    // This function will edit the program
    //-----------------------------------------------------------
    //-------------------------------------------------------------
    //------------------------------------------------------------- //
    
    
    
    
    
    void edit(struct bank_management *data)
    {
         system("cls");
         
         int record =0;
         
         FILE *fdata;
         char id[10];
         char temp[30];
         char x;
         fdata=fopen("record_account.dat", "r+");
         if(fdata==NULL)
         {
                        printf("Unable to open the file\n\n");
                        main();
         } 
         printf("\t\t----------------------\n");
         printf("\t\t    Edit the Account\n");
         printf("\t\t----------------------\n");
            
         
         printf("\n ID \n TITLE \n ADDRESS \n CURRENT BALANCE \n ACCOUNT OPENING DATE \n ACCOUNT TYPE \n");
         printf("---------------------------------------------------------------------------");
               
         rewind(fdata);
         while( fread(data, sizeof(*data), 1, fdata) )
         {
                printf("\n ID =  %s\n Account Title =  %s\n Account Address = %s\n Current Balance =  %s\n Account Opening Date = %s\n Account Type = %s\n", data->id, data->acc_title, data->add_acc_holder, data->curr_balance, data->acc_op_date, data->acc_type);
                printf("\n-----------------------------------------------------------------------------------\n");
         }
         printf("\n\n\n Enter ID to Edit : ");
         scanf("%s", id);
         fflush(stdin);
         rewind(fdata);
         while( fread(data, sizeof(*data), 1, fdata) )
         {
                if(!strcmpi (id, data->id ) )
                {
                           record = 1;
                           printf("\nEnter id:\t");
                           fflush ( stdin ) ;
                           scanf("%s",data->id);
                   
                    
                           printf("\nEnter Name:\t");
                           fflush ( stdin ) ;
                           scanf("%s",data->acc_title);
                           
                           printf("\nEnter Address:\t");
                           fflush ( stdin ) ;
                           scanf("%s",data->add_acc_holder);
                           
                                                 
                           
                           printf("\nEnter Current balance:\t");
                           fflush ( stdin ) ;
                           scanf("%s",data->curr_balance);
                           
                           printf("\nEnter Account opening Date(dd/mm/yyyy):\t");
                           fflush ( stdin ) ;
                           scanf("%s",data->acc_op_date);
                           
                     
                           printf("\nEnter Account Type:\t");
                           fflush ( stdin ) ;
                           scanf("%s",data->acc_type);
                
                            printf("\n ID =  %s\n Account Title =  %s\n Account Address = %s\n Current Balance =  %s\n Account Opening Date = %s\n Account Type = %s\n", data->id, data->acc_title, data->add_acc_holder, data->curr_balance, data->acc_op_date, data->acc_type);
                            printf("\n-----------------------------------------------------------------------------------\n");
         
                           
                           fseek(fdata, -sizeof(*data), SEEK_CUR);
                           
                           fwrite( data, sizeof(*data), 1, fdata );
                     
                     
                           system("pause");
                           
                           main();
                           }
                           
                }      
                if(record==0)
                {
                
                printf("\t\t-------------\n\n");
                printf("\t Record not found\n\n");
                printf("\t Press y to try again\n\n");
                printf("\t press n to return to main menu\n\n");
                           x = getche();
                           fflush(stdin);
                           if( (x=='y') || (x=='Y') )
                           {
                           void edit(struct bank_management *data);
                           }
                           else
                           {
                           main();
                           } 
                  
    }
    }
    
    
    
    
    
    // This function will exit the program
    //-----------------------------------------------------------
    //-------------------------------------------------------------
    //------------------------------------------------------------- //
    
    
    void exit(struct bank_management *data)
    {
         system("cls");
         char close = 'Y';
         printf("Are you sure you want to Exit(Y/N)");
         close = getche(); 
         
         if( (close == 'Y' ) || ( close == 'y') )
         {
             
         exit(0);     
         }
         else
         {
             printf("You have entered the wrong value");
             
         }    
    }
    
    void print(struct bank_management *data)
    {
         FILE *fdata;
         fdata=fopen("record_account.dat","rb");
         while( fread(data, sizeof(*data),1,fdata)==1)
         {
                printf("\t\t\t-----------------\n");
                printf("\t\t\t Account Details\n");
                printf("\t\t\t-----------------\n");
                printf("\n ID =  %s\n Account Title =  %s\n Account Address = %s\n Current Balance =  %s\n Account Opening Date = %s\n Account Type = %s\n", data->id, data->acc_title, data->add_acc_holder, data->curr_balance, data->acc_op_date, data->acc_type);
                printf("\n-----------------------------------------------------------------------------------\n");
         
         }
         fclose(fdata);
         
         
         printf("\n\n\nPress any key to go back to main menu\n\n\n");
         
         
         system("pause");
         
         main();
         }
         
         
         
    int checkNumber(char number[], int allowDots) {
        
        for (int i = 0; i < strlen(number); i++) {    
        
            if (!allowDots)
        
            if (!isdigit(number[i]))
        
            return 0;
        
        }
        
        return 1;
    
    }
    
    int checkLetters(char string[]) {
        
        for (int i = 0; i < strlen(string); i++) {    
              
               if (isdigit(string[i]))
              
                  return 0;
        
        }
        
        return 1;
    
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    So in the last couple of hours, you've basically ignored everything suggested so far and decided to one again try the begging approach.

    Doesn't editing and deleting data from file!

    I'm done caring about you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User andrew89's Avatar
    Join Date
    Dec 2011
    Location
    Indiana, United States
    Posts
    80
    Seriously... I don't know anyone who is going to sift through 728 lines of code to fix your problem... especially when it uses gets(), itoa(), strcmpi(), etc.

    Tried to compile after a rewrite and run, works fine, until it crashes with a seg fault.
    If, for some reason, I don't make any sense at all, it's highly likely that I've been up all night on some strange bender that isn't normal. I likely unarmed and far from dangerous. While I haven't been known to physically harm anyone or anything else, there have been unsubstantiated reports that I have driven others into both a hazy stupor as well as a blinding rage. Otherwise, I hope I helped.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please help on my Payroll system project
    By marchyde07 in forum C Programming
    Replies: 7
    Last Post: 08-09-2010, 11:50 AM
  2. Bank like system
    By Signpost in forum C Programming
    Replies: 20
    Last Post: 03-30-2008, 12:52 PM
  3. Replies: 12
    Last Post: 06-03-2005, 01:13 AM
  4. Operating System Project
    By Pete in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 07-15-2004, 09:33 AM
  5. Simple Bank Account Uni Project Help!!!
    By griff in forum C Programming
    Replies: 3
    Last Post: 05-09-2003, 05:49 PM