// // main.m // chartest // // Created by Kevin Bradley on 9/24/23. // Copyright © 2023 nito. All rights reserved. // #import /* + (NSString *)getNumberWithLimit:(NSInteger)limit { NSString *errorString = @"\nChoose a number, 0 to exit. [1]: "; char c; printf("%s", [errorString UTF8String] ); c=getchar(); while (c > limit) { printf("c = %c", c); c=getchar(); } printf("c = %c", c); return @""; } */ @interface Dumb: NSObject + (NSInteger)getNumberFromPrompt:(NSString *)prompt; @end @implementation Dumb + (NSInteger)getNumberFromPrompt:(NSString *)prompt { char c; char buf[64]; int i = 0; printf("%s", [prompt UTF8String]); c=getchar(); while (c != '\n') { buf[i] = c; i++; c=getchar(); } buf[i] = '\0'; return atoi(buf); } @end int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSInteger limit = 20; NSInteger number = [Dumb getNumberFromPrompt:@"\nChoose a number, 0 to exit. [1]: "]; NSLog(@"number: %lu", number); while (number > limit) { number = [Dumb getNumberFromPrompt:@"\nChoose a number, 0 to exit. [1]: "]; NSLog(@"number: %lu", number); } } return 0; }