int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSDictionary * ProbablyInaccurateFinnishtoEnglshtranslation= [NSDictionary dictionaryWithObjectsAndKeys: @"postilaatikko", @"mailbox", @"oppikirja", @"textbook", @"näppäimistö", @"keyboard", @"piano", @"piano", @"laskukone", @"calculator", @"manteli", @"almond", @"lumi", @"snow", @"vuori", @"mountain", @"aika", @"time", @"kynttilä", @"candle", nil];
NSString * inputSentence;
char cstring[451];
NSArray * sentenceIntoWords;
NSMutableString * translatedSentence;
int i = 0;
NSLog(@"Enter a sentence: \n");
//scanf("%s", &cstring);
gets (cstring);
inputSentence = [NSString stringWithCString: cstring encoding: NSASCIIStringEncoding];
sentenceIntoWords = [inputSentence componentsSeparatedByString: @" "];
for(i=0; i<[sentenceIntoWords count]; i++)
{
if ([ProbablyInaccurateFinnishtoEnglshtranslation objectForKey:[sentenceIntoWords objectAtIndex:i] == nil])
{
translatedSentence = [NSMutableString stringWithString: [sentenceIntoWords objectAtIndex: i]];
}
else {
translatedSentence= [ProbablyInaccurateFinnishtoEnglshtranslation objectForKey: [sentenceIntoWords objectAtIndex: i]];
}
}
NSLog(@"%@", translatedSentence);
[pool drain];
return 0;
}
Я пытаюсь сравнить каждое слово предложения, введенного пользователем, с NSArray, заменяя ключ переведенным словом при сопоставлении.Хорошо, поэтому я изменил это на следующее: if ([последнее слово входного предложения отображается, есть ли ошибка в моей логике?