-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathf01b.cpp
More file actions
47 lines (36 loc) · 870 Bytes
/
f01b.cpp
File metadata and controls
47 lines (36 loc) · 870 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
//Lab Program 1 Part b: Repeat the exercise using an input file specified by the user instead of the standard input and using an output file specified by the user instead of the standard output.
#include<iostream>
#include<string.h>
#include<fstream>
#include<stdlib.h>
using namespace std;
int main()
{
string name, rev;
char infile[30], outfile[30];
fstream fpinp, fpoutp;
int j;
system("clear");
cout<<"Enter the input filename: \n";
cin>>infile;
cout<<"Enter the output filename: \n";
cin>>outfile;
fpinp.open(infile, ios::in);
fpoutp.open(outfile, ios::out);
if(!fpinp||!fpoutp)
{
cout<<"FATAL ERROR!: Unable to open the file(s)";
exit(0);
}
while(fpinp)
{
getline(fpinp, name);
rev.erase();
for(j=name.length()-1; j>=0; j--)
rev+=name[j];
fpoutp<<rev<<endl;
}
fpinp.close();
fpoutp.close();
return 0;
}