memory pointer tricks?

Member
Posts: 38
Joined: 2008.09
Post: #1
I am trying to port some code from C/C++ into Objective-C (doing iphone development) and I wondering if there is a comparable trick as the following:

memory = "foo 100bar";

x = atoi(&memory[0]);
here x is 0

x = atoi(&memory[4]);
here x is 100

Can something be done similar with NSString?
Quote this message in a reply
⌘-R in Chief
Posts: 1,260
Joined: 2002.05
Post: #2
If want memory access then use -[NSString UTF8String] or any of the other methods that get byte data from the string. If you want a substring, then use any of the methods that get a substring.

There's no tricks to be had.
Quote this message in a reply
Member
Posts: 260
Joined: 2005.05
Post: #3
Toontingy Wrote:I am trying to port some code from C/C++ into Objective-C (doing iphone development) and I wondering if there is a comparable trick as the following:

memory = "foo 100bar";

x = atoi(&memory[0]);
here x is 0

x = atoi(&memory[4]);
here x is 100

Can something be done similar with NSString?
What is the "trick"? You are simply passing atoi a pointer to the beginning of the string (where there are no numbers) or to the fifth character, which is a number. In the first case, it finds nothing to interpret as a number, in the second case it does. Trick? This works the same in ObjC since it is straight C code.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  pointer cleanup questions kendric 7 4,616 Mar 29, 2009 07:48 PM
Last Post: kendric
  pointer or not? kensuguro 17 7,880 Aug 15, 2007 04:12 PM
Last Post: AnotherJake
  My AnimationManager didn't like being a pointer. milkfilk 6 3,929 Mar 24, 2007 10:03 PM
Last Post: unknown
  Pointer-related woes (C/C++) sealfin 2 2,688 Jan 18, 2006 01:22 PM
Last Post: sealfin
  Hide Mouse Pointer JonTrainer 9 7,391 Nov 10, 2005 10:46 AM
Last Post: Jordan