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 79 80 81 82 83
|
#include <iostream>
#include <string>
#include <cctype>
#include <fstream>
using namespace std;
//Function Prototypes//
string charString(string*, string*, string*, int, int, int);
string reverseString(string, string, string);
//------------------//
int main()
{
string linePtr1, linePtr2, linePtr3, line01, line02, line03;
// Holds the strings for each line.
string *line1 = &linePtr1;
string *line2 = &linePtr2;
string *line3 = &linePtr3;
// Holds the lenth of each of the lines.
int length1 = 0;
int length2 = 0;
int length3 = 0;
charString(line1, line2, line3, length1, length2, length3);
}
string charString(string *line1, string *line2, string *line3, int length1, int length2, int length3)
{
ifstream inFile;
inFile.open("testdata.txt"); //Opens test .txt file
//Gets the full string line.
getline(inFile, *line1);
getline(inFile, *line2);
getline(inFile, *line3);
string line01 = *line1;
string line02 = *line2;
string line03 = *line3;
//Gets the strings length.
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 << length1 << endl;
cout << length2 << endl;
cout << length3 << endl;
cout << line01 << endl;
cout << line02 << endl;
cout << line03 << endl;
}
/*string reverseString()
{
string line1, line2, 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;
} */
|