I have a similar problem as mentioned in by this guy
C++: Getting random negative values when converting char to int
but i just want to know how to solve the problem and the code should not get more slow. I welcome all suggestions.
I tried to make the char to be unsigned char but that didn't work, then i tried to use this code :
const char char_max = (char)(((unsigned char) char(-1)) / 2);
c = (num & char_max);
but the output was different and i don't know exactly what that code does.
I am still a student.
cout << "\nEnter any string : ";
    cin >> s1;
    for (char& c : s1)
    {
    num = c;
    num= (num+rand())%256;
            // const char char_max = (char)(((unsigned char) char(-1)) / 2);
            //c = (num & char_max)
    c = num;
    }
    cout <<"\n"<< s1;
I expect c to have normal ASCII values so that i can use it back to retrieve the original int value
Thanks!!
 
    