Heyy
i know its possieble to convert char to int with atoi
but is it possible to do it the other way ...
int --> char ??????????????
Heyy
i know its possieble to convert char to int with atoi
but is it possible to do it the other way ...
int --> char ??????????????
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Lets taketo convert it you should pic 3, 2 and 1 seperately. Using thisCode:int dig = 123;Code:int countVar=dig; for(int numOfDigits=0; countVar !=0;numOfDigits++) countVar=countVar/10; char char_array[100]; //Or you can use malloc(): char* char_array=(char*)malloc(numOfDigits+1); for(int i=numOfDigits-1;i>=0;i--) { char_array[numOfDigits-i-1]=char(dig%int(pow(10,(i+1)))/pow(10,i))+'0'; //Plus '0' to convert int to char } char_array[numOfDigits]=NULL;
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
Tell me if it didn't work.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
It's outdated C++ code on a C forum.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Not to mention the rounding errors (and poor performance) when using pow()
it didnt work.. sorry... but thanks anyway
No problem when base is 10.Originally Posted by Salem
>> It doesn't work
To make it work first it should be in C code not C++, second math.h should be included.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
Before this poor thread acquires any further confusion,Originally Posted by Dave_SinkulaCode:#include <stdio.h> int main(void) { char text[11]; int value = 123; sprintf(text, "%d", value); printf("text = \"%s\"\n", text); return 0; } /* my output text = "123" */
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
it worked perfect... thanks