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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <iostream>
#include <string>
#include <cctype>
#include <fstream>
using namespace std;
//Function Prototypes//
void charString(); //Gets the length of the string lines.
string reverseString(string*, string*, string*); //Reverses the String lines.
//------------------//
int main()
{
string line01, line02, line03;
string *line1 = &line01; //
string *line2 = &line02; //Copies pointers to similar variables
string *line3 = &line03; //
charString(); //Get length of string lines.
reverseString(line1, line2, line3); //Reverse the strings.
return 0;
}
void charString()
{
ifstream inFile;
inFile.open("testdata.txt"); //Opens test .txt file
string line01, line02, line03; //Holds the overall string lines.
int length1, length2, length3; //Hold the length of the strings
getline(inFile, line01); //
getline(inFile, line02); //Gets the lines of the .txt file.
getline(inFile, line03); //
//-----------------------------------------------------------------------------------------//
for(int i = 0; i != line01.length(); i++) //Determines isalpha string length for line 1
{
if(isalpha(line01[i]))
{
length1++;
}
}
for(int i = 0; i != line02.length(); i++) //Determines isalpha string length for line 2
{
if(isalpha(line02[i]))
{
length2++;
}
}
for(int i = 0; i != line03.length(); i++) //Determines isalpha string length for line 3
{
if(isalpha(line03[i]))
{
length3++;
}
}
//-----------------------------------------------------------------------------------------//
cout << "The length of line 1: " << length1 << endl; //
cout << "The length of line 2: " << length2 << endl; //outputs the length of lines 1-3 of the .txt file
cout << "The length of line 3: " << length3 << endl; //
}
string reverseString(string *line1, string *line2, string *line3)
{
cout << "Here is the String the correct way." << endl;
cout << *line1 << endl << *line2 << endl << *line3 << endl;
cout << "Here is the String backwards." << endl;
cout << "Nothing here yet :/" << endl;
}
|