views:

413

answers:

4

I am new to Cocoa and need to capture input using scanf to run a program that requires input of four variables one at a time.

Is there any console, window class, canvas, memo class (as in delphi) that will llow me to do this.

Earl Cenac

+3  A: 

You can use stdio with Objective C, which is a complete superset of C.

If your program runs from a command line, you can just write it in C.

Matthew Schinckel
+1  A: 

Objective C is just a an extensions to C, and Objective C++ is an extension to C++. You can use scanf, or if you prefer you can use Objective C++ (rename your implementation files to end with .mm) and use C++ iostreams.

Louis Gerbarg
A: 

You can use NSScanner to parse the input, but as has already been said you use the C standard library to interact with stdin/stdout. I'd use -[NSString initWithUTF8String:] to get the conversion from c string to NSString.

Graham Lee
A: 

Objective-C is simply a set of extensions to C (and a supporting library and API in libobjc), so you have access to everything that any other C program would have. So, just use scanf.

To get the results into an NSString, use +[NSString stringWithUTF8String:] or (less probably) +[NSString stringWithCString:encoding:].

Peter Hosey