I am building a game similar to mastermind for the iPhone and I am needed to compare two strings character by character. I need to choose a string from the database and compare it with the string entered by the player.
I have tried the following but it does not seem to work. Can you please help me.
//create file handle
NSFileHandle *file;
file = [NSFileHandle fileHandleForReadingAtPath:@"4db.txt"];
//read data into file in NSData format
NSData *filedata;
filedata = [file readDataToEndOfFile];
//convert NSData to NSString
NSString *string;
string = [[NSString alloc] initWithData:filedata encoding:NSASCIIStringEncoding];
//convert from string to array
NSArray *lines = [string componentsSeparatedByString:@"\n"];
//take one of the string and store it in sword
NSString *sword = [lines objectAtIndex:0];
//convert string to char
const char *word = [sword UTF8String];
sec[0] = word[0];
sec[1] = word[1];
sec[2] = word[2];
sec[3] = word[3];
I am now assuming sec contains the characters of the string that I read from the file. It does not seem to work. Kindly help. Any other efficient method would b great if you can suggest.