Your dec_to_bin is trying to convert a number to a string of '1's and '0's, but is only returning the first char value
You are defining ret as a char * pointer, but you are using it like a std::string which it is not. It is a pointer to memory, and you have to provide it with some memory to point to. As it is you are overwriting random memory, although in debug mode ret probably is initialised to 0, so you will just get a memory exception.
You could allocate the memory with malloc, but this will lead to a world of pain as the way you call the function will simply result in memory leaks.
If you have to use char* pointers and not std::string then I would suggest passing it a buffer to write the string to. You know the string will always be 8 characters long plus the null terminator
char buffer[9];
dec_to_bin(sum, buffer);
ret += '1' is not doing what you think it does. It is adding a char value to a char* pointer which is totally different. You need to store the character at the location pointed to by ret, and then move ret to point to the next location
*ret = '1';
ret = ret + 1;
or
*ret++ = '1';
When this finishes ret will point to the end of the string, so you can't return that. There is not much benefit from returning a value you passed to the routine, but if you must then you need to save it
char* dec_to_bin(int decimal, char *buffer)
{
char *ret = buffer;
int d = decimal, i;
for (i = 128; i >= 1; i = i/2){
if(d / i){
*ret++ = '1';
d -= i;
}
else
*ret++ = '0';
}
return buffer;
}
You should run this program in a debugger, because that will teach you a lot about what is actually going on in your code