Integer to character array

How to store any integer number (12345) in character array??

I’m not very familiar with c++ but what you can do is take the integer as a string and then using for loop take each character and fill the char array with the characters

rough idea

string s;

cin >> s;

char[] array;

for(int i = 0;i<sizeOftheString;i++)

{

array[i] = s.At(i);

}

I don’t know c++ so I just gave you a rough idea although there might be ways to convert the integer to char array

Hope this helps!!

Extract the digit, and store (digit+48) in the char array.

Eg-

int x;
cin>>x;
char[i]=(char)(x+48);

You can extract digit 1 by 1 by %10 and division by 10.

To convert an integer to ascii digits and store as array of char you can use:

std::string int2str(int x)
{
    std::stringstream ss;
    ss << x;
    return ss.str();
}

int main(int argc, char* argv[])
{
    // digits may be accessed via str.
    std::string str = int2str(12345);

    // to char array (copy digits only; not a valid c-string).
    char* buf = new char[str.size()];
    str.copy(buf, str.size());

    // ...
    delete [] buf;
    return 0;
}
//