I'm new in C++, and I'm trying to write a program that using only function (no vector or template) should be able to read an extarnal file and save everything in one array. To dimension my array i first read the total number of lines in the file, and based on taht I dimensioned my array. Then I re-read all the lines in the file and I started to store them in the array. Everything went well. But when I got the code and tried to make us a feature I got stuck. I can not find any way to pass the array by reference. Each time I find a variety of errors. Can someone help me please? Thank you
while (!infile.eof())
{
// read the file line by line
getline (infile,line);
++lines_count2;
// call a function that take out the tags from the line
parseLine(&allLines[lines_count], lines_count2, line);
} // end while
// FUNCTION PARSE
// Within parseHTML, strip out all of the html tags leaving a pure text line.
void parseLine(string (&allLines)[lines_count], int lines_count2, string line)
{
// I don-t take empty lines
if (line!="")
{
// local var
string del1="<!DOCTYPE", del2="<script";
int eraStart=0, eraEnd=0;
// I don't take line that start with <!DOCTYPE
eraStart = line.find(del1);
if (eraStart!=std::string::npos)
line.clear();
// I don't take line that start with <script
eraStart = line.find(del2);
if (eraStart!=std::string::npos)
line.clear();
//out
cout << "Starting situation: " << line << "\n \n";
// A. counting the occourence of the character ">" in the line
size_t eraOccur = count(line.begin(), line.end(), '<');
cout << "numero occorenze" << eraOccur << "\n \n";
// declaring the local var
string str2 ("<"), str3 (">");
// B. loop in the line for each occurence...looking for < and > position
for (int i=0; i<eraOccur; i++)
{
// looking for position char "<"
eraStart = line.find(str2);
if (eraStart!=string::npos)
{
cout << "first 'needle' found at: " << eraStart << '\n';
// looking for position char ">"
eraEnd = line.find(str3);
if (eraEnd!=string::npos)
cout << "second 'needle' found at: " << eraEnd << '\n';
eraEnd=eraEnd-eraStart+1;
//delete everything between < and >
cout << "start " << eraStart << " end " << eraEnd << "\n \n";
line.erase(eraStart, eraEnd);
}
}
cout << "memo situation: " << line << "\n \n";
// C. memorize the result into an array
allLines[lines_count2] = line;
} // end if
}