-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc.cpp
More file actions
55 lines (45 loc) · 982 Bytes
/
Copy pathc.cpp
File metadata and controls
55 lines (45 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
char rot13(char ch)
{
if ((ch >= 'a') && (ch <= 'z'))
return char((13 + ch - 'a') % 26 + 'a');
else if ((ch >= 'A') && (ch <= 'Z'))
return char((13 + ch - 'A') % 26 + 'A');
else
return ch;
}
string rot13(string str)
{
for (unsigned int i = 0; i < str.length(); i++)
str[i] = rot13(str[i]);
return str;
}
int main()
{
fstream infile;
infile.open("message.in");
if(infile.fail())
{
cout << "Error: could not open input file\n";
exit(EXIT_FAILURE);
}
ofstream outfile;
outfile.open("message.out");
if(outfile.fail())
{
cout << "Error: could not open output file\n";
exit(EXIT_FAILURE);
}
//cout logic
int count = 1;
char line[100];
while (infile.getline(line, 100))
cout << count++ << ":" << rot13(line) << endl;
infile.close();
outfile.close();
return 0;
}