In an objective-c/cocoa app, I am using c functions to open a text file, read it line-by-line and use some lines in a third-party function. In psuedo-code:
char *line = fgets(aFile);
library_function(line); // This function calls for a utf-8 encoded char * string
This works fine until the input file contains special characters (such as accents or the UTF-8 BOM) whereupon the library function outputs mangled characters.
However, if I do this:
char *line = fgets(aFile);
NSString *stringObj = [NSString stringWithUTF8String:line];
library_function([stringObj UTF8String]);
Then it all works fine and the string is outputted correctly.
What is that [NSString...
line doing that I'm not?
Am I doing something wrong with how the line is fetched initially? Or is it something else entirely?