>Using sprintf() wouldn't (i don't think ) help me convert a number into a string to bre sent through a socket.
The end result is the same as the non-standard itoa, a string with the numeric value of an integer.
>What is sorintf anyway?
You don't know what it is yet you say that it won't work for your purposes?
Code:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int DIGITS = 10;
char *itoa ( int n )
{
int sign;
if ( ( sign = n ) < 0 )
n = -n;
int i = 0;
char *s = new char[DIGITS];
do
s[i++] = static_cast<char> ( n % 10 + '0' );
while ( ( n /= 10 ) > 0 );
if ( sign < 0 )
s[i++] = '-';
s[i] = '\0';
std::reverse ( s, s + std::strlen ( s ) );
return s;
}
int main()
{
int i = 12345;
char *p = itoa ( i );
std::cout<< p <<std::endl;
delete p;
char a[10];
std::sprintf ( a, "%d", i );
std::cout<< a <<std::endl;
std::cin.get();
}
-Prelude