Reputation:
How do I get an NSString from console input, and then try to cast it into an int?
Upvotes: 10
Views: 13688
Reputation:
You can also do it directly with scanf. Example
int number = 0;
scanf("%d", &number);
Upvotes: 9
Reputation: 73622
You can read in a char*
string from console (scanf or whatever), like you would in a regular C program. Then, create an NSString
object from it using stringFromCString:withEncoding:
. Finally, use NSString
's integerValue
function to get it's numerical value.
Upvotes: 9