X
x
converting 1944 to '1','9','4','4'
how can I convert a number such as 1944 to a character array?
thanks!
how can I convert a number such as 1944 to a character array?
thanks!
x said:converting 1944 to '1','9','4','4'
how can I convert a number such as 1944 to a character array?
converting 1944 to '1','9','4','4'
how can I convert a number such as 1944 to a character array?
thanks!
Leor Zolman said:int y = 1944;
char buffer[10];
sprintf(buffer, "%d", y);
x said:converting 1944 to '1','9','4','4'
how can I convert a number such as 1944 to a character array?
thanks!
Mike Wahler said:char *array = new char[sz];
std::copy(cs, cs + sz, array);
for(std::string::size_type i = 0; i < sz; ++i)
std::cout << "array[" << i << "] == " << array << '\n';
delete array;
Oops.Leor Zolman said:int y = 1944;
char buffer[10];
sprintf(buffer, "%d", y);
No problem in this case, but on my system, INT_MAX is 2147483647,
which is too big to fit in a 10-character buffer
Howard said:Mike Wahler said:char *array = new char[sz];
std::copy(cs, cs + sz, array);
for(std::string::size_type i = 0; i < sz; ++i)
std::cout << "array[" << i << "] == " << array << '\n';
delete array;
delete [] array;
x said:converting 1944 to '1','9','4','4'
how can I convert a number such as 1944 to a character array?
x said:converting 1944 to '1','9','4','4'
how can I convert a number such as 1944 to a character array?
Siemel Naran said:x said:converting 1944 to '1','9','4','4'
how can I convert a number such as 1944 to a character array?
How about
const size_t N = std::numeric_limits<int>::digits10+1; // is this the right
one?
char array[N];
char * ptr = array;
for ( ; x; x/=10, ++ptr) {
int y = x%10;
*ptr = y + '0';
}
*ptr = 0;
Leor said:Oops.Leor Zolman said:int y = 1944;
char buffer[10];
sprintf(buffer, "%d", y);
No problem in this case, but on my system, INT_MAX is 2147483647,
which is too big to fit in a 10-character buffer
x said:converting 1944 to '1','9','4','4'
how can I convert a number such as 1944 to a character array?
Rolf Magnus said:Can you even imagine how much money that kind of "oops" has already
destroyed?
Leor said:Oops.Leor Zolman <[email protected]> spoke thus:
int y = 1944;
char buffer[10];
sprintf(buffer, "%d", y);
No problem in this case, but on my system, INT_MAX is 2147483647,
which is too big to fit in a 10-character buffer
Can you even imagine how much money that kind of "oops" has already
destroyed?
//
// tostrtest.cpp: Test tostring.h library
//
#include "tostring.h"
int main()
Michiel Salters said:but char mucking is always tricky, and rarely needed.
boost::lexical_cast<std::string>( 1944 ) is easy.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.