Re: [Newbie] writing plain text to a file
Re: [Newbie] writing plain text to a file
- Subject: Re: [Newbie] writing plain text to a file
- From: Ali Ozer <email@hidden>
- Date: Fri, 28 Feb 2003 19:17:59 -0800
- (FILE *)openFile:(NSString *)filename mode:(NSString *)mode
{
FILE *fp;
// man fopen() for modes - add some error checking, too!
if (NULL == (fp = fopen([filename cString]), [mode cString])))
{
return fp;
}
}
Please, do not use [filename cString], ever. This converts the NSString
to the default cString encoding, which depends on the user's language.
It's almost never UTF-8. However, the file system names are almost
always UTF-8. So far any non-ASCII characters, [filename cString] will
give you the wrong result. In addition, [filename cString] might raise
an exception if the conversion cannot be done.
Due to these problems, cString is being deprecated, but in the
meantime, it's good to stay away from it.
If you need to convert NSStrings to "char *" filenames appropriate for
passing to Posix functions, the method fileSystemRepresentation is your
friend. It's in Foundation/NSPathUtilities.h.
Ali
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.