An Access Violation Segmentation Fault. Need Help ASAP

This is a discussion on An Access Violation Segmentation Fault. Need Help ASAP within the C Programming forums, part of the General Programming Boards category; Hi guys! I just encountered the error "An Access Violation Segmentation Fault". I dont know what to do. I really ...

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    2

    An Access Violation Segmentation Fault. Need Help ASAP

    Hi guys! I just encountered the error "An Access Violation Segmentation Fault". I dont know what to do. I really need your help ASAP! Thanks!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <math.h>
    
         void err(){
              printf("\n\n\n     System Error! Exiting Program!");
              return;
              }
         void accnum(int pine, int *pin){
         *pin=(((((pine/2)-500)/3)*4)/2)+10000000+90000;
           
         }
         void pin(int month, int year,int selection,int name,int *pin, int *accountnum){
         int a = 1000,b=rand() % 10,c=25,d=((8*month*selection)/name),i;
         int pine;
         a = (a*month);
         b = (b*year)/10;
         c = (c*selection);
         d = (d*name)/2;
            
    
         pine=a+b+c+d;
         accnum(pine,&*accountnum);
         printf("\n             Your account number is: %d",*accountnum);
         printf("\n             Your pin number is: %d",pine);
         *pin=pine;
         }
         void acc(){//char *acc[10],char *pin[10],char *lname[100]){
         char acccheck[20],pincheck;
         printf("\n\n     WELCOME! You have selected the option to access your account.");
         
         printf("\n\n     Please enter your account number:");
         scanf("%s",&acccheck);
         printf("\n\n     Please enter your P.I.N code:");
         scanf("%s",&pincheck);
         printf("\n\n     WELCOME, Mr. s! Please select your transaction:");//lname);
         printf("\n\n             [1] Current Balance");
          printf("\n\n             [2] Deposit ");
          printf("\n\n             [3] Withdraw");
           printf("\n\n             [c] Cancel Transaction");
    
           
           
         }
         
           
           
        
    void create_CA(char *fname[40],char *lname[40],char *mname[40],int *b_mon,char *con[40],char *tin[40],char *add[40],int *bdate,int *byear,int *ver,int *pin1, int *accno){
         char acc;
         int val1;
         int sel=rand() % 50,a,b;
         printf("\n\n\n\n\n\n\n ");
         printf("\n     Note: Activates only on press of Y and N");
         printf("\n     Would you like to access the account requirement before registering?(Y/N)");
         scanf("%s",&acc);
         
         
         if(acc =='y' || acc =='Y'){
         printf("\n\n             =================================================");
         printf("\n             ++         Checking Account Requirements       ++");
         printf("\n             =================================================");
        
         printf("\n             -A minimum deposit of at least 5000 pesos");
         printf("\n             -Minimum ADB for interest is: ||Percentage|| Minimum balance ADB||");
         printf("\n                                                1.25       5000-24,999");
         printf("\n                                                1.50       25,000-149,999");
         printf("\n                                                1.75       150,000-2,000,000");
         printf("\n                                                2.00       2,000,000++      ");
         val1=1;
         }
         else if(acc =='N' || acc =='n'){
              val1=1;
              }
         else{
              err();
              val1=0;
              return;
              }
                     
         printf("\n\n     You have selected Savings Account. Please fill-in the following details.");
         
         
         printf("\n\n             =================================================");
         printf("\n             ++      Checking Account Registration Form     ++");
         printf("\n             =================================================");
         printf("\n\n             First Name:");
         scanf("%s",&*fname);
          printf("\n             Last Name: ");
          scanf("%s",&*lname);
          printf("\n             Middle Initial: ");
          scanf("%s",&*mname);
           printf("\n             Birthdate:");
           scanf("%d",&*bdate);
           if(*bdate<1 || *bdate>31){
                        err();
                        return;
                        }
           
           printf("\n             Birthmonth:");
           scanf("%d",&*b_mon);
           if(*b_mon<1 || *b_mon>12){
                        err();
                        return;
                        }
           printf("\n             Birthyear:");
           scanf("%d",&*byear);
           if(*byear<1900 || *byear>2010){
                        err();
                        return;
                        }
           printf("\n             Address(City):");
           scanf("%s",&*add);
           printf("\n             Contact Number:");
           scanf("%s",&*con);
           printf("\n             Tax Identification Number:");
           scanf("%s",&*tin);
           printf("\n\n           ");
           b=rand() % 25;
    
           a=*bdate+b;
           printf("\n             Good day! Mr. %s", lname);
           pin(*bdate,*byear,sel,a,&*pin1,&*accno);
           printf("\n             Thank you for registering in KOO ONLINE BANK!");
    
         }
    void create_SA(char *fname[40],char *lname[40],char *mname[40],int *b_mon,char *con[40],char *tin[40],char *add[40],int *bdate,int *byear,int *ver,int *pin1, int *accno){
         char acc;
         int val1;
         int sel=rand()% 35,a,b;
         printf("\n\n\n\n\n\n\n ");
         printf("\n     Note: Activates only on press of Y and N");
         printf("\n     Would you like to access the account requirement before registering?(Y/N)");
         scanf("%s",&acc);
         
         
         if(acc =='y' || acc =='Y'){
         printf("\n\n             =================================================");
         printf("\n             ++         Savings Account Requirements        ++");
         printf("\n             =================================================");
         printf("\n             -A minimum deposit of at least 3000 pesos");
         printf("\n             -Minimum ADB for interest is: ||Percentage|| Minimum balance ADB||");
         printf("\n                                                1.25       3000-24,999");
         printf("\n                                                1.50       25,000-149,999");
         printf("\n                                                1.75       150,000-2,000,000");
         printf("\n                                                2.00       2,000,000++      ");
         val1=1;
         }
         else if(acc =='N' || acc =='n'){
              val1=1;
              }
         else{
              err();
              val1=0;
              return;
              }
                     
         printf("\n\n     You have selected Savings Account. Please fill-in the following details.");
         
         
         printf("\n\n             =================================================");
         printf("\n             ++      Savings Account Registration Form      ++");
         printf("\n             =================================================");
         printf("\n\n             First Name:");
         scanf("%s",&*fname);
          printf("\n             Last Name: ");
          scanf("%s",&*lname);
          printf("\n             Middle Initial: ");
          scanf("%s",&*mname);
           printf("\n             Birthdate:");
           scanf("%d",&*bdate);
           if(*bdate<1 || *bdate>31){
                        err();
                        return;
                        }
           printf("\n             Birthmonth:");
           scanf("%d",&*b_mon);
           if(*b_mon<1 || *b_mon>12){
                        err();
                        return;
                        }
           printf("\n             Birthyear:");
           scanf("%d",&*byear);
           if(*byear<1900 || *byear>2010){
                        err();
                        return;
                        }
           printf("\n             Address(City):");
           scanf("%s",&*add);
           printf("\n             Contact Number:");
           scanf("%s",&*con);
           printf("\n             Tax Identification Number:");
           scanf("%s",&*tin);
           printf("\n\n           ");
           b=rand();
           a=*bdate+b;
           printf("\n             Good day! Mr. %s", lname);
           pin(*bdate,*byear,sel,a,&*pin1,&*accno);
           printf("\n             Thank you for registering in KOO ONLINE BANK!");
           
         }
    void create_CC(char *fname[40],char *lname[40],char *mname[40],int *b_mon,char *con[40],char *tin[40],char *add[40],int *bdate,int *byear,int *ver,int *pin1, int *accno){
         char acc;
         int val1;
         int sel=rand() % 15,a,b;
         printf("\n\n\n\n\n\n\n ");
         printf("\n     Note: Activates only on press of Y and N");
         printf("\n     Would you like to access the account requirement before registering?(Y/N)");
         scanf("%s",&acc);
         
         
         if(acc =='y' || acc =='Y'){
         printf("\n\n             =================================================");
         printf("\n             ++       Credit Card Account Requirements      ++");
         printf("\n             =================================================");
         printf("\n             -Must be at least 18 years old");
         printf("\n             -Every payment has 0.05% interest rate");
         printf("\n             -Every late month of payment has an additional interest rate of 2%");
         val1=1;
         }
         else if(acc =='N' || acc =='n'){
              val1=1;
              }
         else{
              err();
              val1=0;
              return;
              }
                     
         printf("\n\n     You have selected Savings Account. Please fill-in the following details.");
         
         
         printf("\n\n             =================================================");
         printf("\n             ++       Credit Card Account Requirements      ++");
         printf("\n             =================================================");
         printf("\n\n             First Name:");
         scanf("%s",&*fname);
          printf("\n             Last Name: ");
          scanf("%s",&*lname);
          printf("\n             Middle Initial: ");
          scanf("%s",&*mname);
           printf("\n             Birthdate:");
           scanf("%d",&*bdate);
           if(*bdate<1 || *bdate>31){
                        err();
                        return;
                        }
           printf("\n             Birthmonth:");
           scanf("%d",&*b_mon);
           if(*b_mon<1 || *b_mon>12){
                        err();
                        return;
                        }
           printf("\n             Birthyear:");
           scanf("%d",&*byear);
           if(*byear<1900 || *byear>2010){
                        err();
                        return;
                        }
           printf("\n             Address(City):");
           scanf("%s",&*add);
           printf("\n             Contact Number:");
           scanf("%s",&*con);
           printf("\n             Tax Identification Number:");
           scanf("%s",&*tin);
           printf("\n\n           ");
           b=rand();
           a=*bdate+b;
           printf("\n             Good day! Mr. %s", lname);
           pin(*bdate,*byear,sel,a,&*pin1,&*accno);
           printf("\n             Thank you for registering in KOO ONLINE BANK!");
         }
    void create(char *f_name[40],char *l_name[40],char *m_name[40],int *b_mon1,char *con[40],char *tin[40],char *add[40],int *b_date,int *b_year,int *ver,int *pin1, int *accno){
         int o;
         printf("\n\n     WELCOME! You have selected the option to create a new bank account.");
         printf("\n\n             [1] Savings Account");
         printf("\n\n             [2] Checking Account ");
         printf("\n\n             [3] Credit Card Account");
         printf("\n\n             [4] Cancel Transaction");
         printf("\n\n     Please select your bank account:");
         scanf("%d",&o);
    if(o==1){
          create_SA(&*f_name,&*l_name,&*m_name,&*b_mon1,&*con,&*tin,&*add,&*b_date,&*b_year,&*ver,&*pin1,&*accno);
          
          }
    else if(o==2){
          create_CA(&*f_name,&*l_name,&*m_name,&*b_mon1,&*con,&*tin,&*add,&*b_date,&*b_year,&*ver,&*pin1,&*accno);
               }
    else if (o==3){
          create_CC(&*f_name,&*l_name,&*m_name,&*b_mon1,&*con,&*tin,&*add,&*b_date,&*b_year,&*ver,&*pin1,&*accno);
               }
    else if (o==4){
          return;
               }   
           
         }
    
    
    main() //main() is the main function of the program
    {
    
          int i,bmon,b_date,b_year,ver,pin1,accno;   //Creates integer variable
          char *f_name[40],*l_name[40],*m_name[40],*con[40],*tin[40],*add[40];
          hello(&i);
          if(i==1){
          create(&*f_name,&*l_name,&*m_name,&bmon,&*con,&*tin,&*add,&b_date,&b_year,&ver,&pin1,&accno);
          printf("Hello");
          }
          else if(i==2){
              acc();
               }    
    
          
          getch();
          //Getch() requires the user to input a character before proceeding
          }

  2. #2
    Registered User
    Join Date
    Aug 2010
    Posts
    2
    I forgot to post this.

    This is the code above err() function

    Code:
     
    void hello(int *a){
         printf("             =====================================================");
         printf("\n             ++           WELCOME TO KOO ONLINE BANK            ++");
         printf("\n             =====================================================");
    
          printf("\n\n             [1] Create New Bank Account");
          printf("\n\n             [2] Access Bank Account(Not yet available)");
          
          printf("\n\n             =====================================================");
           printf("\n             *  NOTE: Only one account can be registered online. *");
           printf("\n             =====================================================");
          printf("\n\n     Please select your transaction:");
          scanf("%d",&*a);
          
         }

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,687
    First you should delete all instances of &* in your program. It does NOTHING useful. Dereference a pointer and then take the address just gets you back to where you started.

    > scanf("%s",&*fname);
    Now, given your original array of char *f_name[40], what are you expecting to happen here?

    What you DON'T have, is an array of 40 strings you can just read into without any further effort on your part.

    Consider something like
    Code:
    void foo ( char names[][100] ) {
        scanf("%s", names[0] );  // and so on, up to names[9]
    }
    
    int main ( ) {
        char names[10][100];
        foo( names );
        return 0;
    }
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. access violation (segmentation fault)
    By MarlonDean in forum C++ Programming
    Replies: 7
    Last Post: 05-16-2008, 05:02 AM
  2. FtpFileFind access violation with MS VC++ 6.0
    By earth_angel in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2005, 07:02 PM
  3. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  4. strcat segmentation fault
    By captain-cat in forum C Programming
    Replies: 3
    Last Post: 07-20-2004, 10:29 AM
  5. 0xC0000005: Access Violation
    By Strider in forum Windows Programming
    Replies: 3
    Last Post: 11-07-2001, 01:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21