I am trying to read a html file to collect data from it. I am currently having a problem with my output (semantic error). I am supposed to read each individual character while counting them. I am also supposed to specify links and tags (and a few other things but I dont have all that code up yet). I am to assume the character (<) will start a tag and the combination of characters (<a) will start a tag and that the character (>) ends tags and links. I have my code the file im trying to read and the output all listed below. let me know what you think I should do.
~~~~~~~~HERES MY CODE~~~~~~~~
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inFile;
const int SIZE = 65; // Array size for file
char file_name[SIZE];
char ch;
int countChar = 0;
int countLink = 0;
int countTag = 0;
const char OPEN = '<';
const char LOWER = 'a';
const char UPPER = 'A';
const char end = '!';
const char CLOSE = '>';
const char DASH = '-';
char prevChar;
char currChar;
// get the file name
cout << " Please enter a valid filename (no blanks!): " << endl;
cin >> file_name;
//open the file if it exists
inFile.open(file_name, ios::in);
if (!inFile)
{
cout << " The file you have requested does not"
" exist please try agin "<< endl;
return 0;
}
//Get each character from the file and dispay them.
inFile.get(prevChar);
inFile.get(currChar);
countTag = 2;
while (!inFile.eof())
{
while (prevChar == OPEN)
{
while (currChar != CLOSE)
{
if (currChar == LOWER)
{
countLink++;
prevChar = currChar;
}
inFile.get(currChar);
countChar++;
}
if (currChar == CLOSE)
{
countTag++;
prevChar = currChar;
}
inFile.get(currChar);
countChar++;
}
inFile.get(prevChar);
countChar++;
}
// close the file
inFile.close();
cout << "\n\n your countChar is " << countChar << endl;
cout << " \n\n tag count is " << countTag<< endl;
cout << " \n\n link count is " << countLink << endl;
return 0;
}
~~~~~~~~~HERES THE FILE SOURCE~~~~~~~~~
<!--
AUTHOR: A.F. Tyson
VERSION: 1.0.0
PURPOSE: Sample HTML File used to test programming assignment
NOTE: if you want to view this file as HTML, download the
image files it references as well
-->
<HTML>
<HEAD>
<TITLE>COP 3014: Introduction to C++ Programming</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B"
ALINK="#0000EE">