Sign in to follow this  

Noob objective c question (char arrays?)

This topic is 2631 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites

This topic is 2631 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this