Re: Long to C-String
Re: Long to C-String
- Subject: Re: Long to C-String
- From: Julian Barkway <email@hidden>
- Date: Tue, 8 Apr 2003 06:06:55 +0200
On Tuesday, April 8, 2003, at 02:04 am, John C. Randolph wrote:
David Blanton wrote:
On 4/7/03 4:18 PM, "email@hidden" <email@hidden>
wrote:
you could use the ltoa() function in <stdlib.h> as follows:
ltoa( bytesPtr, buffer, 10 );
There is no man page for ltoa and ltoa is not defined in stdlib.h.
Could it
be elsewhere?
Is there no Cocoa class for what seems to be a common need ...
Convert a
long to a sting or am I misssing something here?
How about [NSString stringWithFormat:@"%d"]?
You can go the other way with [NSScanner scanInt:]
There's an easier way:
long int foo;
NSString *digits = [[NSNumber numberWithLong:foo] stringValue];
But he wanted a 'C' String not a Cocoa object....
How about:
char * fooString = [[[NSNumber numberWithLong:foo] stringValue]
cString];
(or UTF8String if you want to avoid deprecated methods)
or even (using bog-standard C):
char fooString [maxlength];
sprintf (fooString, "%d", foo);
_______________________________________________
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.