-
Notifications
You must be signed in to change notification settings - Fork 0
/
reverse.cpp
50 lines (39 loc) · 998 Bytes
/
reverse.cpp
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
/* ====================================================
* File: reverse.cpp #
* This program reverses its source code recursively. #
* Author: @juancarlosfarah #
* ====================================================
*/
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
/* Function: ReversePrint
* ======================
* This function takes in a ifstream and a char
* and reverse prints the contents of the ifstream.
*/
char ReversePrint(ifstream& ifs, char next) {
if (ifs.eof()) {
return next;
}
ifs.get(next);
cout.put(ReversePrint(ifs, next));
return next;
}
/* Function: Main
* ==============
*/
int main() {
ifstream ifs;
ifs.open("reverse.cpp");
if (ifs.fail()) {
cerr << "Opening of input file failed!" << endl;
exit(1);
}
cout.put(ReversePrint(ifs, static_cast<char>(NULL)));
/* add space after output */
cout << "\n\n" << endl;
ifs.close();
return 0;
}