• 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
Problems with NSString: initWithCString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with NSString: initWithCString


  • Subject: Problems with NSString: initWithCString
  • From: Andrew Baldwin <email@hidden>
  • Date: Thu, 28 Mar 2002 01:54:32 -0500

A snippet from my code:
searchString = [[NSString alloc] initWithCString:&(aBuffer[2]);

I get the following error when debugging:

"Unable to determine target of Objective-C method call (ignoring):
Error accessing memory address 0x3: Invalid argument"

In gdb, if I type: "print (char*)&(aBuffer[2])" it prints what I expect, an 88 character long cString... only in the format: "\371\361\314\270\226\207\363\336\350\343\223\....\000"

Why am I getting this error? searchString is simply an NSString* previously set to nil and shouldn't have anything to do with this, so why is there a problem with [[NSString alloc] initWithCString:buffer]? I get the same error even if I change my code so that I can use [[NSString alloc] initWithCStringNoCopy:&(aBuffer[2]) length:(bLength - 2) freeWhenDone:YES].

Sorry if this is very simple and I'm just not seeing the solution,
Andrew
_______________________________________________
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: Problems with NSString: initWithCString
      • From: Ondra Cada <email@hidden>
  • Prev by Date: NSTableView in a sheet
  • Next by Date: Re: Icon Badges
  • Previous by thread: Re: NSTableView in a sheet
  • Next by thread: Re: Problems with NSString: initWithCString
  • Index(es):
    • Date
    • Thread