943,152 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 345
  • C++ RSS
Feb 23rd, 2010
0

C++ encryption text file help

Expand Post »
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??
C++ Syntax (Toggle Plain Text)
  1. void rotateEncrypt(vector<string> V1, vector<string> V2, int rotKey)
  2. {
  3.  
  4. char ch;
  5. int k;
  6. string word = V1[0];
  7. for (unsigned i=0; i<word.size();i++)
  8. {
  9. if(word[i]!=' ')
  10. {
  11. ch = tolower( word[i]);
  12. ch = ch + rotKey;
  13. word[i] = ch;
  14. if(ch > 'z');
  15. k = ch -'z';
  16. ch = 'a'+k - 1;
  17. word[i] = ch;
  18. }
  19. }
  20. V2.push_back(word);
  21. ofstream fo("simpler.txt" ,ios::app);
  22. fo<< word <<'\n';
  23. fo.clear();
  24. fo.close();
  25. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
isralruval is offline Offline
14 posts
since Oct 2009
Feb 23rd, 2010
0
Re: C++ encryption text file help
$ 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 empty body in an ‘if’ statement

Of course, you could have simply stepped this through the debugger and seen that your if statement was useless.
Team Colleague
Reputation Points: 5862
Solved Threads: 949
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: c++ setw & string selection sort modification
Next Thread in C++ Forum Timeline: Can anyone tell me error in this function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC