I wrote this program that takes a text file, inputs it one character at a time. The program counts the number of lines, words, and paragraphs, then outputs them. As the program does this, it also outputs the input file to output.txt without spaces. Problem is, when i run it, it just sits there and does nothing. Been looking at it for an hour, cant figure out why. I know this is extremely vague, but if you have ideas thatd be great.
Code:
#include <iostream>
#include <fstream>
using namespace std;
//prototyping
void initialize(int& words, int& lines, int& paragraphs, char& letter, int& totalWords);
void processBlank(ofstream& output, char& letter, int& words);
void copyText(ofstream& output, char& letter);
void updateCount(int& words, int& lines, int& paragraphs, int& totalWords);
void printTotal(int& lines, int& paragraphs, int& totalWords);
int main()
{
int words, lines, paragraphs, totalWords;
char letter;
initialize(words, lines, paragraphs, letter, totalWords);
ifstream input ("Ch7_Ex7Data.txt");
if (!input)
{
cerr << "The system cannot open the input file.";
exit(1);
}
ofstream output ("output.txt");
if (!output)
{
cerr << "The system cannot open the output file.";
exit(1);
}
letter = input.get();
while (!input.eof())
{
while (letter != '\n')
{
processBlank(output, letter, words);
copyText(output, letter);
}
updateCount(words, lines, paragraphs, totalWords);
letter = input.get();
}
//closing my files
input.close();
output.close();
printTotal(lines,paragraphs,totalWords);
return 0;
}
void initialize(int& words, int& lines, int& paragraphs, char& letter, int& totalWords)
{
words = 0;
lines = 0;
paragraphs = 0;
letter = ' ';
totalWords = 0;
}
void processBlank(ofstream& output, char& letter, int& words)
{
if (letter != ' ')
{
words++;
}
}
void copyText(ofstream& output, char& letter)
{
if (letter != ' ')
output.put(letter);
}
void updateCount(int& words, int& lines, int& paragraphs, int& totalWords)
{
if (words = 0)
{
paragraphs++;
}
words += totalWords;
if (words != 0)
{
lines++;
}
words = 0;
}
void printTotal(int& lines, int& paragraphs, int& totalWords)
{
cout << "Number of words: " << totalWords;
cout << "Number of lines: " << lines;
cout << "Number of paragraphs: " << paragraphs;
}