Thread: signal 10 error

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    37

    signal 10 error

    Useing Xcode I keep getting an error for executable runner: program has exited due to signal 10(SIGBUS).

    This happens anytime I try to input a choice from the menu, so I dont think the code is running the switch statement correctly but I cant find anything wrong with it. Any help would be greatly appreciated.

    Code:
    #include <stdio.h>
    
    int main (void)
    {/*main*/
    	int avg, choice=1, num, sum=0, i, num_max=0;
    	
    	
    	while(choice>=1 && choice<=5)
    	{/* while */
    	
    	printf("Please choose one of the following\n");
    	printf("1. Find the average\n");
    	printf("2. Find the largest\n");
    	printf("3. Exit\n");
    	scanf("%d", choice);
    	
    	
    		switch(choice)
    		{/*switch*/
    			case 1:/*find average */
    				i=0;
    				while(i<10)
    				{/*while*/
    					printf("Enter number:");
    					scanf("%d",num);
    					sum=sum+num;
    					i=i+1;
    				}/*while close*/
    				avg=sum/10;
    				printf("The average of the numbers is: %d\n", avg);
    				break;
    			case 2: /*find max*/
    				i=0;
    				while(i<10)
    				{/*while*/
    					printf("Enter number:");
    					scanf("%d",num);
    					if(num>num_max)
    					num_max=num;
    					i=i+1;
    				}/*while close*/
    				printf("The largest value is: %d\n", num_max);
    				break;
    			case 3:
    				printf("Exiting");
    				break;
    			default:
    				printf("Error");
    				break;
    		}/*end switch*/
    	}/*end while*/
    	
    return(0);
    }/*end main*/

  2. #2
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Code:
    scanf("%d", choice);
    This is incorrect. You need to pass an adress to scanf. This is correct

    Code:
    scanf("%d", &choice);

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    37
    Wow, I feel dumb now. Thanks.

  4. #4
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Everyone did those kind of errors, don't worry. You learn that way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. file reading
    By gunghomiller in forum C++ Programming
    Replies: 9
    Last Post: 08-07-2007, 10:55 PM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Segmentation Fault
    By Lost__Soul in forum C Programming
    Replies: 46
    Last Post: 04-28-2003, 04:24 AM