1: // Filename: ROTATE.CPP
2: // Purpose: Reads in the text of one file, shifts all characters 47 positions
3: // to the right, and outputs the resulting text to a second file.
4: // The shift is actually a circular rotation or "wrap-around".
6: #include <iostream>
7: #include <fstream>
8: #include <string>
9: using namespace std;
11: int main(int argc, char* argv[])
12: {
13: if (argc != 3)
14: {
15: cout << "\nError: Wrong number of parameters. \n"
16: << " Must be exactly two. \n"
17: << "\nCommand Usage: "
18: << "\nrotate source_file destination_file \n";
20: return 1;
21: }
23: const int SHIFT_VALUE = 47;
24: const int HIGHEST_CODE = 125;
25: const int BASE_CODE = 31;
27: ifstream inFile(argv[1]);
28: ofstream outFile(argv[2]);
30: string s;
31: int overHang;
32: int i;
34: while(getline(inFile, s))
35: {
36: for (i = 0; i < s.length(); i++)
37: {
38: overHang = int(s[i]) + SHIFT_VALUE - HIGHEST_CODE;
39: if (overHang > 0)
40: s[i] = char(BASE_CODE + overHang);
41: else
42: s[i] = char(int(s[i]) + SHIFT_VALUE);
43: }
44: outFile << s << endl;
45: }
46: inFile.close();
47: outFile.close();
49: return 0;
50: }