Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
Apple Computing Products:
macOS - Apps and Programs
programming help
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="onwin" data-source="post: 835632" data-attributes="member: 96313"><p>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. </p><p></p><p>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.</p><p></p><p>Can someone help me out? Thanks!</p><p></p><p>// program to reverse the digits of a number 123 -> 321 </p><p>// from Programming in Objective-C 2.0 by Kochan</p><p></p><p>#import <Foundation/Foundation.h></p><p></p><p>int main (int argc, const char * argv[]) {</p><p> NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];</p><p> int number, right_digit;</p><p> </p><p> NSLog (@" Enter number.");</p><p> scanf ("%i", &number);</p><p> getchar (); //the code in the book did not include this part</p><p> </p><p> //NSLog (@"%i", number);</p><p> </p><p> while ( number != 0)</p><p> { right_digit = number % 10;</p><p> NSLog (@"%i", right_digit);</p><p> number /= 10;</p><p> }</p><p> </p><p> [pool drain];</p><p> return 0;</p><p>}</p></blockquote><p></p>
[QUOTE="onwin, post: 835632, member: 96313"] 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]
Verification
Post reply
Forums
Apple Computing Products:
macOS - Apps and Programs
programming help
Top