Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mac > BOOK: Beginning Mac OS X Programming
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 27th, 2010, 07:03 AM
Registered User
 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
Reply With Quote
  #2 (permalink)  
Old May 29th, 2010, 06:52 AM
Registered User
 
Join Date: Apr 2010
Location: West Wellow, England
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #3 (permalink)  
Old May 30th, 2010, 03:14 PM
Registered User
 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
  #4 (permalink)  
Old May 31st, 2010, 09:35 AM
Registered User
 
Join Date: Apr 2010
Location: West Wellow, England
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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;
}
Reply With Quote
  #5 (permalink)  
Old May 31st, 2010, 04:26 PM
Registered User
 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #6 (permalink)  
Old June 6th, 2010, 06:25 PM
Registered User
 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks MarkR1

MarkR1, Thanks for your help. I figured out what I was doing wrong.
Reply With Quote
  #7 (permalink)  
Old June 7th, 2010, 01:58 PM
Registered User
 
Join Date: Apr 2010
Location: West Wellow, England
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Fantastic! Sorry I couldn't help more - I'm also still working my way through this book
Reply With Quote
  #8 (permalink)  
Old November 3rd, 2010, 01:48 PM
Registered User
 
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Patrick View Post
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?
__________________
Thanks,
David
Reply With Quote
  #9 (permalink)  
Old November 4th, 2010, 11:17 PM
Registered User
 
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Smile 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!
__________________
Thanks,
David
Reply With Quote
  #10 (permalink)  
Old November 9th, 2010, 02:24 PM
Registered User
 
Join Date: Apr 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Calculator page 79

Enter expression 44+7 and shift+return and you get the result.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 01: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 09:59 AM
Calculator DweeLer Other Programming Languages 1 November 18th, 2005 07:13 AM
calculator kale_tushar C++ Programming 1 January 28th, 2004 12:09 PM



All times are GMT -4. The time now is 11:06 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.