Hi..
I am opening a text file containing language data and reading it into a dictionary. The code retrieves all the data, but I can`t get the encoding right. Characters in the text file like for instance "Â" gets translated to "√Ç" instead of "å".
I`m starting to get really annoyed by this problem, and i really appreciate if someone can help me out...
CODE:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *path = [[NSBundle mainBundle] pathForResource:[defaults objectForKey:@"language"]
ofType:@"properties"];
NSMutableDictionary *languageDictionary = [[NSMutableDictionary alloc] init];
char character[1024];
FILE *languageData = fopen([path cStringUsingEncoding:NSISOLatin1StringEncoding], "r");
if (languageData == NULL) NSLog([path stringByAppendingString:@" not found"]);
else
{
//check if end of line flag is set, and end while if so
while (!feof(languageData))
{
fgets(character, 1024, languageData);
NSString *stringFromChar = [NSString stringWithCString:character length:strlen(character)];
NSArray *stringFromCharArray = [stringFromChar componentsSeparatedByString:@" = "];
if(2 == [stringFromCharArray count])
{
[languageDictionary setObject:[stringFromCharArray objectAtIndex:1] forKey:[stringFromCharArray objectAtIndex:0]];
}
}
fclose(languageData);
}