Results 1 to 3 of 3
  1. #1
    newbie programming question

    Member Since
    Apr 09, 2009
    Posts
    3
    Question newbie programming question
    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;
    }

  2. #2
    newbie programming question

    Member Since
    Mar 15, 2007
    Posts
    161
    Specs:
    17" MacBook Pro, 2.33GHz C2D, 2GB RAM
    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.

  3. #3
    newbie programming question

    Member Since
    Apr 09, 2009
    Posts
    3
    here are my outputs
    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.
    153
    (

    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.
    0

    The Debugger has exited with status 0.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Question about Programming
    By mag709 in forum iOS Development
    Replies: 2
    Last Post: 05-17-2012, 04:19 PM
  2. Newb Programming Question
    By OIzq in forum OS X - Operating System
    Replies: 3
    Last Post: 06-29-2011, 09:09 AM
  3. Newbie wanting to learn about Programming Concepts on a Mac
    By c1ph3rtxt in forum OS X - Development and Darwin
    Replies: 7
    Last Post: 04-09-2010, 12:41 AM
  4. newbie question about programming languages
    By MacGal in forum OS X - Development and Darwin
    Replies: 10
    Last Post: 03-28-2008, 08:52 PM
  5. Game Programming Question.
    By shelflife19 in forum OS X - Development and Darwin
    Replies: 2
    Last Post: 11-23-2007, 06:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •