Re: getCString a good idea here?
Re: getCString a good idea here?
- Subject: Re: getCString a good idea here?
- From: Neil Earnshaw <email@hidden>
- Date: Sun, 13 Jul 2003 09:32:47 +0100
Basically, this means that getCString isn't a method for
NSConstantString. So your problem isn't that you're using getCString
improperly, it's that getCString doesn't exist. There is a method
called getCString: (notice the ':'), but that, like all Cocoa methods
that start with get... means that the method returns a value by
reference
The documentation says that -(void)getCString:(char*)buffer _takes_ a
reference and puts a _copy_ of the chars in the area pointed to, rather
than returning a reference. Is this the usual convention for
get<Something> accessors? (I'm a bit of a newbie myself and I've never
come across it in any of the books.)
(which is not what you want), like
char *myCString;
[myString getCString:&myCString];
Wouldn't the '&' mean you are supplying the address of a pointer to a
char, i.e. a char**?
Don't forget, you have to provide the space for the chars to go
into.Something like,
#define ENOUGH_SPACE 256
...
char myCString[ENOUGH_SPACE + 1]; // +1 for the trailing NULL
[myString getCString:myCString];
or you could malloc the space,
char* myCString = NULL;
...
myCString = malloc( sizeof(char) * (ENOUGH_SPACE+1) );
[myString getCString:myCString];
...
free(myCString);
_______________________________________________
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.