![]() |
![]() |
#1 (permalink) | ||
Devils Cabana Boy
Location: Central Coast CA
|
Simple C question
the general purpose is to enter 3 variables and manipulate them the problem is that the program compiles with 0 errors but crashes when i enter a variable.
i get an aplication error (pop up box with the red X) error: Quote:
code of the program Quote:
__________________
Donate Blood! "Love is not finding the perfect person, but learning to see an imperfect person perfectly." -Sam Keen |
||
![]() |
![]() |
#2 (permalink) | |
Banned
Location: shittown, CA
|
You had your quotes on your scanf's in the wrong place. It needs to go:
scanf("format strings", variables); like so: scanf("%d", &bob); Simple typo bug. ![]() fixed code: Quote:
bob:~ johnwort$ ./out Please enter a value for the room width:50 Please enter a value for the room length::50 Please enter a value for the room height::42 The area of the floor of the room is: 2500The volume of the room is: -26072The ratio of the width to the length is: 1072693248 Last edited by juanvaldes; 02-03-2004 at 11:03 PM.. |
|
![]() |
![]() |
#3 (permalink) |
Location: Waterloo, Ontario
|
Ah, the glory/shame of scanf() comes to light!
In many ways, scanf() is a very poor function to use because of it's ease of destruction (just as you've pointed out), it's lack of error reporting, and general lack of robustness. It's generally advised to use gets() to get the input string and then parse it yourself, with a combination of conversion functions, like atoi() and atof()... Anyway, your problem, specifically, is that you're not supplying a variable assignment. You're just supplying a format string and that's bad! Code:
scanf("%d, &nRoomLength"); // this is what you are doing scanf( "%d", &nRoomLength); // this is what you should be doing... Learn your lesson, now! |
![]() |
![]() |
#4 (permalink) | |
Junkie
Location: San Francisco
|
Quote:
|
|
![]() |
![]() |
#6 (permalink) | |
Location: Waterloo, Ontario
|
Quote:
|
|
![]() |
![]() |
#7 (permalink) |
Junkie
Location: San Francisco
|
getline is in the GNU C library and is indeed a different function than the STL getline, but since Microsoft apparently does like buffer overflows, it doesn't seem to be in theirs.
![]() char buffer[256]; fgets(buffer, 256, stdin); |
![]() |
Tags |
question, simple |
|
|