• 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: A question I'm ashamed to ask
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A question I'm ashamed to ask


  • Subject: Re: A question I'm ashamed to ask
  • From: Basil Achermann <email@hidden>
  • Date: Wed, 20 Oct 2004 22:43:24 +0200

On 20.10.2004, at 20:51, Sherm Pendley wrote:

On Oct 20, 2004, at 1:48 PM, April Gendill wrote:

Ok. I work with plain old ansi c so little that this has escaped me. In one of my application I need to take a plain old C character array
and make it into a string but the string needs to use a conversion character.

so I basically I need
char * something = "%x", someInteger;

basically I need to convert the integer into it's hex value and place it in the string.
I can't figure out how to do this.

The simplest "pure C" solution is the sprintf() function - but as with many plain ol' C tasks, there are potential hidden gotchas - you need to allocate the buffer that something points to yourself, it can't point to a constant string, and it must be large enough to hold the hex representation of someInteger.



Use asprintf, much safer than sprintf.

char *something;
asprintf(&something, "....

Even though you don't need to allocate anything, you still have to free "something" yourself of course.


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: A question I'm ashamed to ask
      • From: Sherm Pendley <email@hidden>
References: 
 >A question I'm ashamed to ask (From: April Gendill <email@hidden>)
 >Re: A question I'm ashamed to ask (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: Left Fixed Header in a Scrolling View
  • Next by Date: Process creation notification
  • Previous by thread: Re: A question I'm ashamed to ask
  • Next by thread: Re: A question I'm ashamed to ask
  • Index(es):
    • Date
    • Thread