• 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: Long to C-String
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Long to C-String
      • From: Kyle Moffett <email@hidden>
References: 
 >Re: Long to C-String (From: "John C. Randolph" <email@hidden>)

  • Prev by Date: How-To: private framework
  • Next by Date: Re: How-To: private framework
  • Previous by thread: Re: Long to C-String
  • Next by thread: Re: Long to C-String
  • Index(es):
    • Date
    • Thread