Reputation:
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
Upvotes: 0
Views: 909
Reputation: 11
NSString *password=@"rajan";
NSString *scanpass;
char currentpass[10];
NSLog(@"Enter your old password tp compare");
scanf("%s",currentpass);
scanpass = [NSString stringWithUTF8String:currentpass];
//if([password isEqualToString: @"rajan"])
if([password isEqualToString: scanpass])
NSLog(@"Correct Password");
else
NSLog(@"Wrong Password");
Upvotes: 1
Reputation: 96333
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:]
.
Upvotes: 0
Reputation:
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.
Upvotes: 0
Reputation: 43452
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.
Upvotes: 1
Reputation: 35629
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.
Upvotes: 3