how to convert from int to char*?

In C++17, use std::to_chars as: std::array<char, 10> str; std::to_chars(str.data(), str.data() + str.size(), 42); In C++11, use std::to_string as: std::string s = std::to_string(number); char const *pchar = s.c_str(); //use char const* as target type And in C++03, what you’re doing is just fine, except use const as: char const* pchar = temp_str.c_str(); //dont use cast

Convert an integer to an array of digits

The immediate problem is due to you using <= temp.length() instead of < temp.length(). However, you can achieve this a lot more simply. Even if you use the string approach, you can use: You need to make the same change to use < newGuess.length() when printing out the content too – otherwise for an array of length 4 (which has … Read more

Is there any difference between 1U and 1 in C?

On most compliers, both will give a result with the same representation. However, according to the C specification, the result of a bit shift operation on a signed argument gives implementation-defined results, so in theory 1U << i is more portable than 1 << i. In practice all C compilers you’ll ever encounter treat signed left shifts the same … Read more