Converting Int Value to a string
Ok my code work, but only to a limit of 10 digits, can someone tell me why it wont work after the 10th digit
I'm making this to emulate a Delphi function call IntToStr.
Code:
int main(int argc, char *argv[])
{
int number;
cout<<"Enter a number: ";
cin>>number;
cout<<endl;
int x;
int rema, count, digits;
rema = 1;
rema = number;
digits = 0;
while (rema != 0) {
// calculate how many digits int has
rema = rema / 10;
digits++;
}
char numstr[digits];
count = digits - 1;
int left = number;
while (count >= 0) {
// stick the numbers into an array of char startign from then end so they will be in order
numstr[count] = (left % 10) + '0';
left = left / 10;
count--;
}
string answer = numstr;
cout<<numstr<<endl<<answer<<endl;
system("PAUSE");
return 0;
}