What I'm trying to do is compare each word of a sentence entered by the user with the NSArray, replacing the key with the translated word when matching. Is there a way to run through an NSDictionary, or would I be better off with using the NSArray for the FinnishtoEnglshtranslation (that way I can compare the elements using integers)?
I'm getting a bunch of garbage with the output.
I'm getting a bunch of garbage with the output.
Code:
NSArray * ProbablyInaccurateFinnishtoEnglshtranslation= [NSArray arrayWithObject: @"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 check = 0;
int i, j;
NSLog(@"Enter a sentence: \n");
gets (cstring);
inputSentence = [NSString stringWithCString: cstring encoding: NSASCIIStringEncoding];
sentenceIntoWords = [inputSentence componentsSeparatedByString: @" "];
for(i=0; i<[sentenceIntoWords count]; i++)
{
for(j=0; j<[ProbablyInaccurateFinnishtoEnglshtranslation count]; (j+2)){
if([[sentenceIntoWords objectAtIndex:i] containsObject: [ProbablyInaccurateFinnishtoEnglshtranslation arrayWithObject: j]){
translatedSentence= [NSMutableString stringWithString: [ProbablyInaccurateFinnishtoEnglshtranslation arrayWithObject: (j+1)];
check = 1;
break;
}
else
check = 0;
}
if(check == 0)
translatedSentence = [NSMutableString stringWithString: [sentenceIntoWords objectAtIndex: i]];
}
NSLog(@"%@", translatedSentence);
Last edited by a moderator: