New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

Start a Discussion

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

newbie programming question

Post Reply New Thread Subscribe

Thread Tools

Member Since: Apr 09, 2009
Posts: 3
onwin is on a distinguished road

onwin is offline
I'm learning how to program with Objective C 2.0. I don't have any previous experience. I am using the book "Programming in Objective-C 2.0 by Kochan.

I'm not sure why the following program isn't working. The original program in the book doesn't have the getchar() function. But that didn't work. I found out that scanf also reads the "enter" as "endl" so I inserted getchar. But this still doesn't work.

Can someone help me out? Thanks!

// program to reverse the digits of a number 123 -> 321
// from Programming in Objective-C 2.0 by Kochan

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int number, right_digit;

NSLog (@" Enter number.");
scanf ("%i", &number);
getchar (); //the code in the book did not include this part

//NSLog (@"%i", number);

while ( number != 0)
{ right_digit = number % 10;
NSLog (@"%i", right_digit);
number /= 10;

[pool drain];
return 0;
QUOTE Thanks

Member Since: Mar 15, 2007
Posts: 161
mystic_fm will become famous soon enough
Mac Specs: 17" MacBook Pro, 2.33GHz C2D, 2GB RAM

mystic_fm is offline
People might have a better chance of making suggestions if you were to explain specifically in what way the program isn't working for you.
QUOTE Thanks

Member Since: Apr 09, 2009
Posts: 3
onwin is on a distinguished road

onwin is offline
Typing in intergers like 153 doesn't do anything. Typing in ( or ) or 0 get's "status 0" message.

[Session started at 2009-04-22 23:12:01 -0400.]
2009-04-22 23:12:01.884 prog5.8[280:10b] Enter number.

The Debugger has exited with status 0.
[Session started at 2009-04-22 23:12:12 -0400.]
2009-04-22 23:12:12.236 prog5.8[281:10b] Enter number.

The Debugger has exited with status 0.
QUOTE Thanks

Post Reply New Thread Subscribe

« terminal compiling help | darwinports can't install sqlite3 »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Starter
Last Post
Newbie has question about iPhoto doctorxring Switcher Hangout 0 05-14-2006 09:29 PM
mac newbie question (iWeb) Emuleem22 Switcher Hangout 4 03-02-2006 10:03 PM
Newbie Question rsjackman87 Switcher Hangout 4 05-10-2005 02:12 PM
Newbie question on wireless laptop? Big Dog Dad Switcher Hangout 3 06-12-2004 09:03 AM
Newbie question on best internet browser Big Dog Dad Switcher Hangout 18 05-24-2004 09:34 PM

All times are GMT -4. The time now is 01:52 PM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.

Welcome to

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!

(4 digit year)

Already a member?