From 90dcd3412c374ae74ffe050637221dff60e98f57 Mon Sep 17 00:00:00 2001 From: Matthew Ellison Date: Sun, 13 May 2018 22:26:42 -0400 Subject: [PATCH] Fixed warning about comparing signed and unsigned integer types --- SourceFiles/Atbash.cpp | 6 +++--- SourceFiles/Caesar.cpp | 4 ++-- SourceFiles/Morse.cpp | 6 +++--- SourceFiles/Playfair.cpp | 12 ++++++------ SourceFiles/Vigenere.cpp | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/SourceFiles/Atbash.cpp b/SourceFiles/Atbash.cpp index f038563..2189531 100644 --- a/SourceFiles/Atbash.cpp +++ b/SourceFiles/Atbash.cpp @@ -29,7 +29,7 @@ Atbash::~Atbash(){ */ void Atbash::setInputString(std::string input){ //Strip all punctuation and whitespace from input and make all letters capital - for(int cnt = 0;cnt < input.size();++cnt){ + for(unsigned int cnt = 0;cnt < input.size();++cnt){ char letter = input[cnt]; //If it is upper case add it to the inputString if(isupper(letter)){ @@ -68,7 +68,7 @@ std::string Atbash::getOutputString() const{ */ std::string Atbash::encode(){ //Step through every element in the inputString and shift it the correct amount - for(int cnt = 0;cnt < inputString.size();++cnt){ + for(unsigned int cnt = 0;cnt < inputString.size();++cnt){ outputString += (inputString[cnt] + 25 - (2 * (inputString[cnt] - 'A'))); } @@ -94,7 +94,7 @@ std::string Atbash::encode(std::string input){ * @return The decoded inputString (outputString) */ std::string Atbash::decode(){ - for(int cnt = 0;cnt < inputString.size();++cnt){ + for(unsigned int cnt = 0;cnt < inputString.size();++cnt){ outputString += (inputString[cnt] + 25 - (2 * (inputString[cnt] - 'A'))); } diff --git a/SourceFiles/Caesar.cpp b/SourceFiles/Caesar.cpp index cbab675..460db88 100644 --- a/SourceFiles/Caesar.cpp +++ b/SourceFiles/Caesar.cpp @@ -79,7 +79,7 @@ std::string Caesar::getOutputString() const{ */ std::string Caesar::encode(){ char temp; //A temperary holder for the current working character - for(int cnt = 0;cnt < inputString.size();++cnt){ + for(unsigned int cnt = 0;cnt < inputString.size();++cnt){ temp = inputString.at(cnt); //If it is a upper case letter shift it and wrap if necessary if(isupper(temp)){ @@ -130,7 +130,7 @@ std::string Caesar::encode(int shiftAmount, std::string input){ */ std::string Caesar::decode(){ char temp; - for(int cnt = 0;cnt < inputString.size();++cnt){ + for(unsigned int cnt = 0;cnt < inputString.size();++cnt){ temp = inputString.at(cnt); //If it is an upper case letter shift it and wrap if necessary if(isupper(temp)){ diff --git a/SourceFiles/Morse.cpp b/SourceFiles/Morse.cpp index e31667d..b6ab55e 100644 --- a/SourceFiles/Morse.cpp +++ b/SourceFiles/Morse.cpp @@ -34,7 +34,7 @@ void Morse::setEncodeInputString(std::string input){ //Make sure the input is empty to begin std::string temp; //Step through every element in input, removing anything that is not a letter and making all letters uppercase - for(int cnt = 0;cnt < input.size();++cnt){ + for(unsigned int cnt = 0;cnt < input.size();++cnt){ char letter = input[cnt]; //If it is a letter or number add it to the inputString, turning all letters capital if(isalnum(letter)){ @@ -54,7 +54,7 @@ void Morse::setEncodeInputString(std::string input){ void Morse::setDecodeInputString(std::string input){ std::string temp; //Step through every element in input, removing everything except . or - - for(int cnt = 0;cnt < input.size();++cnt){ + for(unsigned int cnt = 0;cnt < input.size();++cnt){ char letter = input[cnt]; //If it is a letter or number add it to the inputString, turning all letters capital if(letter == '.' || letter == '-' || letter == ' '){ @@ -95,7 +95,7 @@ std::string Morse::encode(){ std::string temp = inputString.str(); //Loop through every element in the input string and see what type it is //while(!inputString.eof()){ - for(int cnt = 0;cnt < temp.size();++cnt){ + for(unsigned int cnt = 0;cnt < temp.size();++cnt){ char letter; //Get the next character in the input letter = temp[cnt]; diff --git a/SourceFiles/Playfair.cpp b/SourceFiles/Playfair.cpp index 00c3f8a..968514f 100644 --- a/SourceFiles/Playfair.cpp +++ b/SourceFiles/Playfair.cpp @@ -45,7 +45,7 @@ void Playfair::createGrid(){ //Add any new leters from the keyword to the grid ///If you reach row 5 then the entire grid has been filled char current; - for(int cnt = 0;(cnt < keyword.size()) && (row < 5);++cnt){ + for(unsigned int cnt = 0;(cnt < keyword.size()) && (row < 5);++cnt){ current = keyword[cnt]; //If the current letter needs to be replaced, do so if(current == REPLACED){ @@ -176,7 +176,7 @@ std::string Playfair::encode(){ char letter1, letter2; int row1, col1, row2, col2; //Step through every element in the input string and encode a pair - for(int cnt = 1;cnt < inputString.size();cnt += 2){ + for(unsigned int cnt = 1;cnt < inputString.size();cnt += 2){ //Grab two elements from the input string and search the grid for them letter1 = inputString[cnt - 1]; letter2 = inputString[cnt]; @@ -250,7 +250,7 @@ std::string Playfair::decode(){ char letter1, letter2; int row1, col1, row2, col2; //Step through every element in the input string and encode a pair - for(int cnt = 1;cnt < inputString.size();cnt += 2){ + for(unsigned int cnt = 1;cnt < inputString.size();cnt += 2){ //Grab two elements from the input string and search the grid for them letter1 = inputString[cnt - 1]; letter2 = inputString[cnt]; @@ -323,7 +323,7 @@ void Playfair::setKeyword(std::string key){ //Make sure the keyword is blank keyword = ""; //Remove all punctuation and make everything capital - for(int cnt = 0;cnt < key.size();++cnt){ + for(unsigned int cnt = 0;cnt < key.size();++cnt){ //If it is an upper case letter, just add it to the keyword if(isupper(key[cnt])){ keyword += key[cnt]; @@ -356,7 +356,7 @@ void Playfair::setInputString(std::string input){ //Make sure inputString is empty inputString = ""; //Remove all punctuation and make everything capital - for(int cnt = 0;cnt < input.size();++cnt){ + for(unsigned int cnt = 0;cnt < input.size();++cnt){ char temp = input[cnt]; if(isupper(temp)){ //If the letter is the character than needs replaced, replace it @@ -377,7 +377,7 @@ void Playfair::setInputString(std::string input){ } //Check if anything is doubled and needs bumped down by DOUBLED - for(int cnt = 1;cnt < inputString.size();){ + for(unsigned int cnt = 1;cnt < inputString.size();){ char letter1, letter2; //Get two adjacent letters and compare them letter1 = inputString[cnt - 1]; diff --git a/SourceFiles/Vigenere.cpp b/SourceFiles/Vigenere.cpp index 4442156..5bc3f8f 100644 --- a/SourceFiles/Vigenere.cpp +++ b/SourceFiles/Vigenere.cpp @@ -35,7 +35,7 @@ void Vigenere::setInputString(std::string input){ inputString = ""; //Loop through every character in input. Remove all whitespace and punctuation and make sure all letters are capital and add it to inputString - for(int cnt = 0;cnt < input.size();++cnt){ + for(unsigned int cnt = 0;cnt < input.size();++cnt){ char letter = input[cnt]; if(isupper(letter)){ inputString += letter; @@ -74,7 +74,7 @@ void Vigenere::setKeyword(std::string key){ //Make sure the keyword is blank keyword = ""; //Loop through every letter in the key and make sure all of them are uppercase letters - for(int cnt = 0;cnt < key.size();++cnt){ + for(unsigned int cnt = 0;cnt < key.size();++cnt){ char letter = key[cnt]; if(isupper(letter)){ keyword += letter; @@ -134,7 +134,7 @@ std::string Vigenere::encode(){ outputString.reserve(inputString.size()); //Step through every charater in the inputString and advance it the correct amount, according to offset - for(int cnt = 0;cnt < inputString.size();++cnt){ + for(unsigned int cnt = 0;cnt < inputString.size();++cnt){ char letter = (inputString[cnt] + offset[cnt % offset.size()]); //By using % you allow it to loop without having a separate counter //Make sure the character is still a letter, if not, wrap around if(letter < 'A'){ @@ -174,7 +174,7 @@ std::string Vigenere::decode(){ outputString.reserve(inputString.size()); //Step through every charater in the inputString and reduce it the correct amount, according to offset - for(int cnt = 0;cnt < inputString.size();++cnt){ + for(unsigned int cnt = 0;cnt < inputString.size();++cnt){ char letter = (inputString[cnt] - offset[cnt % offset.size()]); //By using % you allow it to loop without having a separate counter if(letter < 'A'){ letter += 26;