So I have to write a program where it gets the name of an input file and output file (if they're identical I am to get an error message) and pass them as arguments to a function called RevFile.
RevFile reads the input file one line at a time, and copies them to the output file, but in reverse. (ex: abc would be cba), and when the end of the input file is reached RevFile returns total number of lines written to the caller.
Things I am told I'm supposed to use: .getline() to fetch null-terminated cstring
arrays to derive the index location and move backwards one character at a time in the array until you reach index location zero
strlen function to help see how many characters in the input file
Any help appreciated
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <cstring>
usingnamespace std;
constint LEN=256;
int main()
{
ifstream inData[LEN];
ofstream outData[LEN];
cout << "Enter the name of an input file: ";
cin.getline(inData, LEN);
cout << "Enter the name of an output file: ";
cin.getline(outData, LEN);
You mentioned: use: .getline() to fetch null-terminated cstring. getline() will only work with a c++ string. See: http://www.cplusplus.com/reference/string/string/getline/?kw=getline
You can use the getline that is a member of istream for c-strings.