你好,有人会介意解释这段代码的含义吗?

时间:2017-10-29 23:26:50

标签: c++

基本上,我的朋友写了这段代码并做了我在这三行中所做的事情,而我的几乎是一页,我不明白这意味着有人可以帮忙。

msg[i] = toupper(msg[i]);
msg[i] = ((msg[i] - 'A')+rotation)%26;
printf("%c", calpha[msg[i]]);

1 个答案:

答案 0 :(得分:2)

// convert a - z character to upper case A - Z
msg[i] = toupper(msg[i]);

// A - Z values are 65 - 90. Subtract from uppercase character 65 (which is A)
// which moves it to 0 - 25 range. Add some shift value to it (rotation)
// %26 brings it back to 0 - 25 range.
msg[i] = ((msg[i] - 'A')+rotation)%26;

// print calpha value for given index (our 0 - 25 result)
printf("%c", calpha[msg[i]]);
相关问题