signal 10 (SIGBUS)

This is a discussion on signal 10 (SIGBUS) within the C Programming forums, part of the General Programming Boards category; ok new problems... Here is what I have when I run the program: Code: [Session started at 2005-11-12 19:45:55 -0500.] ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    31

    signal 10 (SIGBUS)

    ok new problems...

    Here is what I have when I run the program:
    Code:
    [Session started at 2005-11-12 19:45:55 -0500.]
    Please enter your name 
    darth
    Please enter your password 
    23456
    please enter a correct name 
    Darth
    please enter a correct password 
    23456
    
    Final Project has exited due to signal 10 (SIGBUS).
    [Session started at 2005-11-12 19:49:13 -0500.]
    Please enter your name 
    darth
    Please enter your password 
    23456
    please enter a correct name 
    leia
    please enter a correct password 
    12345
    
    Final Project has exited due to signal 10 (SIGBUS).
    Here is what my code looks like:
    Code:
     /*William Edward McFadden */
    
    /* Location of all files is at: */
    /* /users/williammcfadden/Documents/school/EGR 115/Final Project/    */
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    /* function Declarations */
       int password(FILE *);
    
        main()
       {
       
       
          FILE *Fpassword;
          FILE *Fplanes;
          FILE *Fdistout;
       
          Fpassword=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/password.txt", "r");
          Fplanes=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/planes.txt", "w");
          Fdistout=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/distlog.out", "w");
         
       /**************************************************  **********************************************/  
       /**************************************************  **********************************************/ 
       
       /*password function */
          password(Fpassword);
          if (Fpassword == 1);
          {
             printf("Sorry you really should not be using this program \n");
             system ("pause");
             exit(0);
          }
       
       
       
          printf("hello ya'll \n");
       
       
          fclose(Fpassword);
          fclose(Fplanes);
          fclose(Fdistout);
       
       }
    
    
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/
            
            
            
        int password(FILE *Fpassword)
       {
          char  NAME[50];
          int PASSWORD;
          int l;
          char* name[6];
          for(l=0; l<6; l++)
          {
             name[l]= malloc        (50);
          }
          int  password[6];
          int i;
          int h;
          int R;
          int z;
            
            
          for(i=0; i<6; i++)
          {
             fscanf(Fpassword, "%s",name[i]);
             fscanf(Fpassword, "%d",&(password[i]));
          }
            
          printf("Please enter your name \n");
          scanf("%s", NAME);
          printf("Please enter your password \n");
          scanf("%i", &PASSWORD);
            
          for(h=0; h<6; h++)
          {
             if(0==strcmp(NAME, name[h]) && PASSWORD == password[h])
             {
                return 1;
             }
             else {
                printf("please enter a correct name \n");
                scanf("%s",NAME);
                printf("please enter a correct password \n");
                scanf("%i",PASSWORD);
                for(R=0; R<6; R++)
                {
                   if (0==strcmp(NAME, name[R]))
                   {
                      if (PASSWORD== password[R])
                      {
                         return 1;
                      }
                   }
                }
                {
                   printf("ONE LAST TIME BUDDY \n");
                                    
                   printf("please enter your name \n");
                   scanf("%s", NAME);
                   printf("please enter your password");
                   scanf("%i", PASSWORD);
                   for(z=0; z<6; z++)
                   {
                      if( 0==strcmp(NAME, name[z]))
                      {
                         if (PASSWORD == password[z])
                         {
                            return 0;
                         }
                      }
                   }
                }
             }
          }
       }
    
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    31
    Sorry, I forgot the question..
    what is sigbus code 10??

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    You've really got a lot of issues with this code. For instance:
    Code:
    if (Fpassword == 1);
    Fpassword is declared as a FILE type. Fpassword normally either returns a pointer to the open file or a null pointer value if a file open error occurred. Also, a semicolon should not be after an if statement. It negates the condition test.

    I would suggest that you pass the file name to the password function. Then open the file in the password function, do the processing, close the file and return a value dependent upon the successs or failure of the processing.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Aside from all the standard non-compliance in your code, there are a couple spots that can generate errors. First you never check the result from fopen() calls before you start using the file handles. Next, if any of your fscanf() calls fail to input a string into the string buffer, your strcmp() calls will overrun the buffer. My best guess is your program is failing on the strcmp() calls. Try printing out the strings before you compare them, and see what happens.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    31
    OK I took your advice, now the program continues to ask again and again if you did not give give the correct answer. ALSO I can only use leia and password 12345, I can not use any of the other names and passwords from the text file password.txt:
    Code:
    leia 12345
    darth 23456
    r2d2 34567
    solo 45678
    jabba 56789
    yoda 67890
    Here is the program (all edited and such)
    Code:
    /* Location of all files is at: */
    /* /users/williammcfadden/Documents/school/EGR 115/Final Project/    */
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
    
    /* function Declarations */
       int password(FILE *);
    
        main()
       {
       
       
          FILE *Fpassword;
          FILE *Fplanes;
          FILE *Fdistout;
       
          Fpassword=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/password.txt", "r");
          Fplanes=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/planes.txt", "w");
          Fdistout=fopen("/users/williammcfadden/Documents/school/EGR 115/Final Project/distlog.out", "w");
         
       /**************************************************  **********************************************/  
       /**************************************************  **********************************************/ 
       
       /*password function */
          password(Fpassword);
          if (Fpassword == 0)
          {
             printf("Sorry you really should not be using this program \n");
             system ("pause");
             exit(0);
          }
    	  printf("\n\n\n\n");
       
       
          printf("hello ya'll \n");
       
       
          fclose(Fpassword);
          fclose(Fplanes);
          fclose(Fdistout);
    	  exit(0);
       }
    
    
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/
            
            
            
        int password(FILE *Fpassword)
       {
          char  NAME[50];
          int PASSWORD;
          int l;
          char* name[6];
          for(l=0; l<6; l++)
          {
             name[l]= malloc(50);
          }
          int  password[6];
          int i;
          int h;
          int R;
          int z;
            
            
          for(i=0; i<6; i++)
          {
             fscanf(Fpassword, "%s",name[i]);
             fscanf(Fpassword, "%d",&(password[i]));
          }
            
          printf("Please enter your name \n");
          scanf("%s", NAME);
          printf("Please enter your password \n");
          scanf("%i", &PASSWORD);
            
          for(h=0; h<6; h++)
          {
             if(0==strcmp(NAME, name[h]) && PASSWORD == password[h])
             {
                return 1;
             }
             else {
                printf("please enter a correct name \n");
                scanf("%s", NAME);
                printf("please enter a correct password \n");
                scanf("%i", &PASSWORD);
                for(R=0; R<6; R++)
                {
                   if(0==strcmp(NAME, name[R]) && PASSWORD == password[R])
                      {
                         return 1;
                      
                   }
                }
                   printf("ONE LAST TIME BUDDY \n");
                   printf("please enter your name \n");
                   scanf("%s", NAME);
                   printf("please enter your password \n");
                   scanf("%i", &PASSWORD);
                   for(z=0; z<6; z++)
                   {
                      if(0==strcmp(NAME, name[z]) && PASSWORD == password[z])
                         {
                            return 0;
                         }
                      }
                   }
                
    			}
    		 }
          
       
    
    /**************************************************  **********************************************/
    /**************************************************  **********************************************/

  6. #6
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    To avoid duplicating my post twice, please see my last post.

    The errors in that post, mainly the two scanf() errors (cause of your crash) and the FILE * == int comparision error still exist. (As well as the memory leaking.) And do try not to double-thread stuff, it really does not speed up help.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading a file
    By nhubred in forum C++ Programming
    Replies: 3
    Last Post: 05-21-2009, 11:34 AM
  2. A-Star Pathfinding
    By mike_g in forum General AI Programming
    Replies: 1
    Last Post: 08-05-2007, 04:18 PM
  3. Segmentation Fault
    By Lost__Soul in forum C Programming
    Replies: 46
    Last Post: 04-28-2003, 04:24 AM
  4. Scheduling Algo
    By BigDaddyDrew in forum C++ Programming
    Replies: 41
    Last Post: 03-08-2003, 10:00 AM
  5. Heaps...
    By Nutshell in forum C Programming
    Replies: 14
    Last Post: 04-23-2002, 08:54 AM

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