• 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: Problem mac os X version 10.6 when using sprinft
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem mac os X version 10.6 when using sprinft


  • Subject: Re: Problem mac os X version 10.6 when using sprinft
  • From: Alastair Houghton <email@hidden>
  • Date: Fri, 7 May 2010 21:50:46 +0100

On 7 May 2010, at 21:16, Sean McBride wrote:

> Also, you should never use sprintf.  Use snprintf instead.

snprintf() is safer, certainly, but "never" is a little strong for my taste.  Like goto or longjmp(), it depends who is using it and what for.

*Anyway*, this is cocoa-dev, and that being the case, this entire question is off-topic.  So to bring it back *on* topic, a better alternative would be to use NSString's -stringWithFormat: method, which is safer than sprintf() or snprintf(), and means you get an NSString object which is a much richer type than a plain C string.  -stringWithFormat: also supports pretty much the same set of specifiers that printf() does, with the addition of %@, of course.

Oh, and there's also NSNumberFormatter if you want to format numbers in a more sophisticated manner.

Kind regards,

Alastair.

--
http://alastairs-place.net



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Problem mac os X version 10.6 when using sprinft
      • From: "Sean McBride" <email@hidden>
References: 
 >Problem mac os X version 10.6 when using sprinft (From: paul morel <email@hidden>)
 >Re: Problem mac os X version 10.6 when using sprinft (From: Fritz Anderson <email@hidden>)
 >Re: Problem mac os X version 10.6 when using sprinft (From: "Sean McBride" <email@hidden>)

  • Prev by Date: Re: Problem with font display
  • Next by Date: Re: 10.5 vs. 10.6 [NSMenu accessibilityIsIgnored] exception
  • Previous by thread: Re: Problem mac os X version 10.6 when using sprinft
  • Next by thread: Re: Problem mac os X version 10.6 when using sprinft
  • Index(es):
    • Date
    • Thread