Okay so I\'m having troubled understanding how to count the numberof characters,
ID: 3616713 • Letter: O
Question
Okay so I'm having troubled understanding how to count the numberof characters, lines, tags, comments, links, and characters withinthe tags in a text file. I can count the characters and lines butwhen ever I try to count the tags, comments, and links it messes upmy character count. here is what i have.#include <iostream> // includestandard I/O routines
#include <fstream>
#include <string> // includeC++ string class header
using namespace std;
int main ()
{
const char TAG_OPEN = '<',
TAG_CLOSE = '>',
LINK_CAP = 'A',
LINK_LOW = 'a',
COMMENT = '!',
EOLN = ' ';
int lineCount = 0,
chCount = 0,
tagCount = 0,
commentCount = 0,
linkCount = 0;
string fileName;
ifstream inFile;
char ch;
cout << "Enter a valid filename (noblanks!): ";
cin >> fileName;
inFile.open (fileName.c_str());
ch = inFile.get();
while (inFile)
{
if (ch != EOF)
chCount++;
if (ch == EOLN)
lineCount++;
if (ch == TAG_OPEN &&inFile.ignore(100, TAG_CLOSE))
tagCount++;
if (ch == TAG_OPEN &&inFile.ignore(100, COMMENT))
commentCount++;
}
}
Explanation / Answer
Update: Posted the code that is giving me problems.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.