Noob objective c question (char arrays?)

Started by
1 comment, last by Timptation 13 years, 6 months ago
I'm a c++ programmer trying to pick up objective c. I'm going through some rough tutorials and want to print out some exception info:

printf( "%s: %s\n", [[e name] cString], [[e reason] cString] );

This leaves me with a warning about cString being depricated. I've been looking into the new way to do it, which appears to be NSString's getCString method. This takes in a buffer which is my problem. I'm not seeing how to make one at the moment. Here's my bad code:

char* buf[] = [[char[128] alloc] init];
char* buf2[] = [[char[128] alloc] init];
printf( "%s: %s\n", [[e name] getCString: buf], [[e reason] getCString: buf2] );

Clearly that's not right, but some google searches have only shown me to assign a char array to a string literal. Can someone correct me? Thanks!

EDIT: getCString actually takes a few more arguments, I know. That's not my issue though.
Advertisement
You should probably go with UTF8String, actually.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Awesome. Thanks!

This topic is closed to new replies.

Advertisement