Re: A question I'm ashamed to ask
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