Reputation: 2811
I'm total newbie so please forgive me if im doing something terrible here.
Im trying to take the user birthday in the format I specify in the example, but getting error in the scanf
section: format specified type char * but the argument has type NSString
How can I fix it? this is my code:
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSString *input;
NSLog(@"Please enter your birthday, for example: 09-01-1984");
scanf("%s", &input);
NSDate *today = [NSDate date];
NSDate *bDay = [NSDate dateWithNaturalLanguageString:input];
NSLog(@"%lu", [bDay elapsedDays:today]);
}
return 0;
}
Upvotes: 2
Views: 152
Reputation: 122391
sscanf()
is part of the C-library and NSString
is part of the Foundation Objective-C framework and you cannot mix them like that.
Try this:
int main(int argc, const char * argv[])
{
@autoreleasepool {
char input[80];
NSLog(@"Please enter your birthday, for example: 09-01-1984");
scanf("%s", input);
NSDate *today = [NSDate date];
NSDate *bDay = [NSDate dateWithNaturalLanguageString:[NSString stringWithUTF8String:input]];
NSLog(@"%lu", [bDay elapsedDays:today]);
}
return 0;
}
Upvotes: 3