I have this assignment that reads in files and then analyzes them. I've gotten it to read, count the number of characters, the number of tags, and lines. I can't get it to count the number of comments, links, number of characters in the tags or the percentage of characters in tags. This is an html file by the way.
Here's an example of how the output should be:
Analysis of file
----------------
Number of lines: 9
Number of tags: 8
Number of comments: 1
Number of links: 1
Number of chars in file: 176
Number of chars in tags: 87
Percentage of characters in tags: 49.43%
To start, string literals should be enclosed in double quotes and character literals are enclosed in single quotes. It appears that the a single character, ch, is being compared against a string. In the code above, ch will only contain a single character at a time.
For example:
1 2
string s = "a string"; // could be empty (""), or contain 1 or more characters
char ch = '\n'; // exactly 1 character
Also, on line 64, I suspect that you meant to use the logical or (||) not logical and (&&).
Start by moving the get call on line 75 to the top of the loop (remove the one on line 47) and move the cout statement down to the bottom of the loop. That way you can test the character before you decide to output it.
Then, add a clause to check for '<' that will then proceed to check the next character if it matched. Here's a simple example:
1 2 3 4 5 6 7 8 9 10 11 12 13
if( '<' == ch )
{
// we have a '<', so we need to see what's next
// Note: output ch before we overwrite it with the next one and
// remember to increment charCount
cout << ch;
inputFile.get( ch );
if( 'a' == ch )
{
// we have "<a"
}
}