Cast from char to int loses precision

I have those program and everything I want to cast a char to ASII I get an error

#include <iostream>
#include <cstdlib>
using namespace std;

void converter(char OriginalChar, int Key);
int main()
char OriginalChar[16] = ":mmZ\\dxZmx]Zpgy",answer;
int Key;

for (Key = 0; Key <= 100; Key++)
if ((int)OriginalChar - Key < 32)
answer = ((((int)OriginalChar - Key) + 127) - 32); //Decrypts the code
answer = ((int)OriginalChar - Key); //Decrypts the code
cout << (char)answer;
return 0;

It would help if you gave the error message(s) and the line(s) that they apply to.

Plus I have no idea what your code is supposed to do.
It all looks a bit odd.

OriginalChar is an array of characters.
When it is cast to an integer (int)OriginalChar the result is the address of the array, as an int. Subtract key from that and you get a number corresponding to the address of some memory location before the start of the array. None of that really makes sense to me, I've no idea what it is supposed to do.

The line where the compiler warns of loss of precision is where an integer value is assigned to char answer. In some circumstances that might be acceptable, here I can't say, but I suspect that is a relatively minor issue in code which has more serious problems.

Topic archived. No new replies allowed.