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;
}
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;
}