Nov 9, 2012 at 1:23pm UTC
Hi,
I want to pass an int to a function that expects a char *. Programming in Linux, so can't use itoa.
The function header looks like this:
void swapEndian(char *pElement, unsigned int uNumBytes)
and calling the function with an int (I know, this won't work..)
1 2
int numLine;
swapEndian(numLine, sizeof (int ));
So what must I do to
numline
to pass it to this function?
Last edited on Nov 9, 2012 at 1:23pm UTC
Nov 9, 2012 at 1:28pm UTC
Try the following
swapEndian( reinterpret_cast<char *>( &numLine ), sizeof(int));
Nov 9, 2012 at 1:40pm UTC
reinterpret_cast is C++. Maybe this was not the correct forum to ask the question as I'm programming C, but if anyone can give me a C solution, will be appreciated.
Nov 9, 2012 at 2:57pm UTC
If your function requires a character string, then you could use sprintf() to make the int into a string.