Hello, everyone.
I'm having a problem with a corrupted stack and I have no idea what the problem is.
I defined a function to receive a character as input and spit out a binary representation in a string:
If I ignore the compiler warning, there's nothing wrong with the result, but it keeps telling me that, "the stack around the variable j has been corrupted."Code:string to_binary_c(char c) { int k = 0; unsigned char j, i = static_cast<unsigned char>(c); string t; for(((j = ~0U) >>= 1)++; j > 0; j >>= 1, k++) i & j ? t += '1' : t += '0'; return t; }
BTW, I'm calling the function from within another function which does the same thing as the above but only does it with a character pointer:
Any help would be appreciated.Code:string to_binary_cp(char* cp) { int k = 0, s_len = strlen(cp); string t, u; for(int i = 0; i < s_len; i++) { u = to_binary_c(cp[i]); u += '-'; t += u; } t.resize(t.size() - 1, '\0'); return t; }