On Dec 31, 2008, at 4:23 PM, Ron Fleckner wrote:
        const int stringLength = [aString length];
        char reverseChars[stringLength];
        for (i = stringLength - 1, j = 0; i >= 0; i--, j++)
        {
                char c = [aString characterAtIndex:i];
                reverseChars[j] = c;
        }

Unfortunately, this is not correct; -[NSString characterAtIndex:] returns a unichar, which is not a char. In addition, it will give odd results for composed characters. Depending on what you want, you might be able to use rangeOfComposedCharacterAtIndex:.

I'd also use NSMutableString instead of a stack buffer of chars, since this looks like a buffer overflow (unless I'm missing something):

reverseChars[j] = '\0';// create a C (UTF8) string by adding a null char


--
Adam

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to