Added tolower() calls

This commit is contained in:
datalore 2023-10-24 21:38:29 +02:00
parent 23eac17117
commit f17af835d4
3 changed files with 5 additions and 4 deletions

View File

@ -5,7 +5,7 @@ void shift(char* text, int key)
std::cout << key << ": "; std::cout << key << ": ";
for(int i = 0; text[i] != 0; ++i) for(int i = 0; text[i] != 0; ++i)
{ {
char c = text[i]-key; char c = std::tolower(text[i])-key;
if(c < 'a') c+=26; if(c < 'a') c+=26;
if(c > 'z') c-=26; if(c > 'z') c-=26;
std::cout << c; std::cout << c;

View File

@ -1,4 +1,5 @@
#include <iostream> #include <iostream>
#include <cctype>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -14,7 +15,7 @@ int main(int argc, char** argv)
for(int i = 0; text[i] != 0; ++i) for(int i = 0; text[i] != 0; ++i)
{ {
char c = text[i]+key; char c = std::tolower(text[i])+key;
if(c < 'a') c+=26; if(c < 'a') c+=26;
if(c > 'z') c-=26; if(c > 'z') c-=26;
std::cout << c; std::cout << c;

View File

@ -2,7 +2,7 @@
int keyvalue(char c) int keyvalue(char c)
{ {
return c - 'a'; return std::tolower(c) - 'a';
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -20,7 +20,7 @@ int main(int argc, char** argv)
int ki = 0; int ki = 0;
for(int pi = 0; text[pi] != 0; ++pi) for(int pi = 0; text[pi] != 0; ++pi)
{ {
char c = text[pi] + keyvalue(key[ki]); char c = std::tolower(text[pi]) + keyvalue(key[ki]);
if(c < 'a') c+=26; if(c < 'a') c+=26;
if(c > 'z') c-=26; if(c > 'z') c-=26;
std::cout << c; std::cout << c;