 |
BOOK: Beginning Mac OS X Programming  | This is the forum to discuss the Wrox book Beginning Mac OS X Programming by Michael Trent, Drew McCormack; ISBN: 9780764573996 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning Mac OS X Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 27th, 2010, 07:03 AM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Debugging Changes to Calculator, p79
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?
|
|

May 29th, 2010, 06:52 AM
|
|
Registered User
|
|
Join Date: Apr 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Patrick,
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.
|
|

May 30th, 2010, 03:14 PM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
After Run->Console
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.
|
|

May 31st, 2010, 09:35 AM
|
|
Registered User
|
|
Join Date: Apr 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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;
}
|
|

May 31st, 2010, 04:26 PM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Still GDB: Running...
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
|
|

June 6th, 2010, 06:25 PM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks MarkR1
MarkR1, Thanks for your help. I figured out what I was doing wrong.
|
|

June 7th, 2010, 01:58 PM
|
|
Registered User
|
|
Join Date: Apr 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Fantastic! Sorry I couldn't help more - I'm also still working my way through this book 
|
|

November 3rd, 2010, 01:48 PM
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Patrick
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?
|
|

November 4th, 2010, 11:17 PM
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Solution to calculator issue
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!
|
|

November 9th, 2010, 03:24 PM
|
|
Registered User
|
|
Join Date: Apr 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Calculator page 79
Enter expression 44+7 and shift+return and you get the result.
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Calculator |
AdamPembs |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 |
2 |
January 31st, 2010 02:48 PM |
| calculator |
mojtaba rashidi |
Visual Studio 2005 |
0 |
March 17th, 2008 07:29 AM |
| Scientific calculator |
NEO1976 |
Flash (all versions) |
2 |
November 28th, 2007 10:59 AM |
| Calculator |
DweeLer |
Other Programming Languages |
1 |
November 18th, 2005 08:13 AM |
| calculator |
kale_tushar |
C++ Programming |
1 |
January 28th, 2004 01:09 PM |
|
 |