You are currently viewing the BOOK: Beginning Mac OS X Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
On page 79, Try It Out, Debugging Changes to Calculator, item 6. Change case '-': at line 26 to case '*':, when I build and run the project, all I get at the bottom right hand of the frame is GBD: Running.... Any idea what I am doing wrong?
You are not doing anything wrong. You just need to do next step over the page and go Run->Console. The GDB: Running... message is mentioned earlier on Pg72. GDB is GNU debugger.
MarkR1, thanks for the response. But even after I choose Run->Console and get the Debugger Console request to Enter an expression and enter 44 + 7, I still only have the phrase GDB: Running, but don't get the reply listed in the book, 44 + 7 = 51, Debugger stopped, etc (point 18 on page 73). I get nothing after point 17 on page 72, Figure 3-14.
It sounds like there's something wrong in the code either in main or Calculator. Have you tried putting some diagnostic printfs to write out values at various stages? For example print out the value of result in Calculator.c before it returns this back to main.c
Here's my code which works. Maybe compare it to yours to see if there's any differences.
main.c
Code:
#include <stdio.h>
#include <stdlib.h>
#include "Calculator.h"
int main (int argc, const char * argv[]) {
int a, b, count, answer;
char op;
// print the prompt
printf("Enter an expression: ");
// get the expression
count = scanf("%d %c %d", &a, &op, &b);
if(count != 3)
{
printf("bad expression\n");
return 1;
}
//perform the computation
answer = calculate(a, b, op);
// print the answer
printf("%d %c %d = %d\n", a, op, b, answer);
return 0;
}
Calculator.c
Code:
/*
* Calculator.c
* Calculator
*
* Created by Mark Rosewood on 26/05/2010.
*
*/
#include "Calculator.h"
#include <stdio.h>
#include <stdlib.h>
int calculate(int a, int b, char operator)
{
int result;
switch (operator)
{
case '+':
result = a + b;
break;
case '-':
result = a - b;
break;
case '*':
result = a - b;
break;
default:
printf("unknown operator: %c\n", operator);
exit(1);
}
return result;
}
MarkR1, Thanks again for all your help, but even after using the downloadable code from Wrox once and on a later occasion copying your code, I still only get the data below in the Debugger Console with GDB: Running... in the lower left hand corner of the Debugger window. After copying your code, running Build Results and getting Build succeeded, then Run ->Run, Run->Console, I get the prompt below but once I enter something like 45 + 8, the cursor just moves to the next line in the Debugger Console and blinks.
The Debugger has exited with status 0.
[Session started at 2010-05-31 16:10:43 -0400.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1461.2) (Fri Mar 5 04:43:10 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger…
Program loaded.
run
[Switching to process 2736]
Running…
Enter an expression: 44 +7
MarkR1, thanks for the response. But even after I choose Run->Console and get the Debugger Console request to Enter an expression and enter 44 + 7, I still only have the phrase GDB: Running, but don't get the reply listed in the book, 44 + 7 = 51, Debugger stopped, etc (point 18 on page 73). I get nothing after point 17 on page 72, Figure 3-14.
Hi Patrick, I am having the same issue with the calculator (p.72-73) exercise. I am able to build/compile with no errors. When I try the run>run and run>console and enter the '44 + 7' problem I get no response. I have checked my code and am not seeing any problems. What was the solution you found?
I found my problem with the caculator program was the numeric keypad. The program does not like me to use the numeric keypad, but will execute correctly if I use the numbers in the regular keyboard. I have not a clue why this is happening but I am moving on!