I’m working on my fourth c lab for my programming class, and i get a “Bus error” I’ve been looking at my code, and looking at the examples my instructor gave, and i can’t figure out whats wrong… can someone please help?
here’s the program….
//——————————————————————————————————————-
//lab4.c
#include <stdio.h>
main ()
{
//——declare data
int x, y, z;
char code;
//——prompt and scan for data
printf(“Please enter a value for Xn”);
scanf(”%d”,&x);
printf(“Please enter a value for Yn”);
scanf(”%d”,&y);
//——decide, operate, and display output
printf(“Would you like to (a)dd, (s)ubtract, (m)ultiply, or (d)ivide the values?n”);
scanf(”%c”,code);
if ( code == ‘a’ )
z = x + y;
printf(“x + y = %dn”,z);
if ( code == ‘m’ )
z = x * y;
printf(“x * y = %dn”,z);
if ( code == ‘s’ )
z = y - x;
printf(“y - x = %dn”,z);
if ( code == ‘d’ )
z = x / y;
printf(“x / y = %dn”,z);
return;
}
//——————————————————————————————————————
and the output….
//——————————————————————————————————————
[localhost:/Developer/C Programming (labs)] l0u13% cc lab4.c -o lab4
[localhost:/Developer/C Programming (labs)] l0u13% ./lab4
Please enter a value for X
2
Please enter a value for Y
3
Would you like to (a)dd, (s)ubtract, (m)ultiply, or (d)ivide the values?
Bus error
[localhost:/Developer/C Programming (labs)] l0u13%
//——————————————————————————————————————
it doesn’t give me a chance to enter the value for code, just x, y, and BOOM.. bus error…
//——————————————————————————————————————
ps. I found about pico on tech tv today (go brett larson!!) and I love it, I’ve also got my terminal hacked (well.. customized) to perfection.. black w/ white text and 33% transparency, I love it!!
_________________
Peace,
-Louie

“‘INTEL INSIDE’—The World’s Most Widely Used Warning Label”
“The box said “Windows ‘95 or Better”... so I got a Mac.”
<font size=-1>[ This Message was edited by: L0u13 on 2002-03-14 15:53 ]</font>




11” MacBook Air 1.6GHz dual-core Intel Core i5: $829.00 Delivered
Samsung S22B300B 21.5” LED Backlit LCD Monitor: $129.99 Delivered
Canon imageCLASS Monochrome Multifunction Laser Printer: $129.99 Delivered
