First of all, im new to coding and I thought sometime about the problem and I tried to google it. I already have a workaround I just want to know if it is possible in another way. Im taking the cs50 course and I should write an encryption function.
My problem is, that my char gets temporarily bigger then 127 and then gets truncated. So is it nevertheless possible to calculate with a certain char temporarily before I save it it into a memory address and truncate it?
The part where I think the problem should be:
for
(int i = 0; i < strlen(ui); i++)
{
if
(isupper(ui[i]))
{
ui[i] += key;
if
(ui[i] > 90)
{
ui[i] -= 26;
}
}
if
(islower(ui[i]))
{
ui[i] += key;
if
(ui[i] > 122)
{
ui[i] -= 26;
}
}
and it gets truncated e.g. if the key gets bigger then 6 for an input of z.
So can I write it somehow, that the 26 gets subtracted before it gets into storage or is (what I think atm) not possible because as soon as it gets bigger then 127 even if it is in one line, it gets truncated?
Workaround ( I thought about writing now): I will subtract 96 before so I get calculate with numbers between 1 and 27 and add it after.
thank you for advice in advance.