• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: getCString a good idea here?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: getCString a good idea here?
      • From: Prachi Gauriar <email@hidden>
    • Re: getCString a good idea here?
      • From: Sherm Pendley <email@hidden>
References: 
 >Re: getCString a good idea here? (From: Prachi Gauriar <email@hidden>)

  • Prev by Date: Rendezvous
  • Next by Date: categories question...
  • Previous by thread: Bug in Xcode, File Inspector lies to me.. (was: Re: How to construct Unicode Safe Strings in the source?)
  • Next by thread: Re: getCString a good idea here?
  • Index(es):
    • Date
    • Thread