i have the following code which works, well its suppose to shift the letters of a text file by whatever the user wants, lets say the text file says "hi" if the user wants to shift the letters by 1 to the right it will become "ij"
ok but the problem is when i want to shift a letter that goes over the alphabet, like lets say the word is "zoo" if i want to shift it by one the letter z will give me a random character that i dont want, the whole word should become "app"
anybody wants to help me fix this??

void rotateEncrypt(vector<string> V1, vector<string> V2, int rotKey)
{

  char ch;
  int k;
  string word = V1[0];
  for (unsigned i=0; i<word.size();i++)
    {
      if(word[i]!=' ')
        {
          ch = tolower( word[i]);
          ch = ch + rotKey;
          word[i] = ch;
          if(ch > 'z');
          k = ch -'z';
          ch = 'a'+k - 1;
          word[i] = ch;
        }
    }
  V2.push_back(word);
  ofstream fo("simpler.txt" ,ios::app);
  fo<< word <<'\n';
  fo.clear();
  fo.close();
}
$ g++ -W -Wall -O2 -c foo.cpp
foo.cpp: In function ‘void rotateEncrypt(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, int)’:
foo.cpp:21: warning: suggest braces around [B]empty body[/B] in an ‘if’ statement

Of course, you could have simply stepped this through the debugger and seen that your if statement was useless.

This article has been dead for over six months. Start a new discussion instead.