Thanks for the advice, fredizzimo,
I fixed the program relative to your comments. Now it works perfectly (though not exactly the way the book wanted it to).
For my fellow ultra-noobs out there, here's a simple program that copies text from one file to another, counting the words, lines, and paragraphs (where paragraph splits are marked by a line with no words on it).
#include<fstream>#include<iostream>using namespace std;void initialize(int&y, int& z, int&w);void processBlank(ifstream& in, ofstream& out, char& ch, int& linesTotal, int& paraTotal);void copyText(ifstream& in, ofstream& out, char& ch, int& w);void printTotal(int& wordsTotal, int& linesTotal, int& paraTotal, ofstream& y);int main(){ int wordsTotal; int linesTotal; int paraTotal; char letter; ifstream inData; ofstream outData; inData.open("E:inData.txt"); outData.open("E:outData.dat"); initialize(wordsTotal, linesTotal, paraTotal); inData.get(letter); while (!inData.eof()) { processBlank(inData, outData, letter, linesTotal, paraTotal); copyText(inData, outData, letter, wordsTotal); } printTotal(wordsTotal, linesTotal, paraTotal, outData); inData.close(); outData.close(); cout << endl; return 0;}//////////////////////////////////////////////////////////////////////////part of the assignment/////////////////////////////////////////void initialize(int&y, int& z, int& w){ y = 0; z = 0; w = 0; return;}/////////////////////////////////////////////////////////////////////////////processBlanks is used to cout the end of lines and new paragraphs,//new paragraphs are indicated as a line with nothing on it.///////////////////////////////////////////////////////////////////////////void processBlank(ifstream& in, ofstream& out, char& ch, int& linesTotal, int& paraTotal){ char peeker; while ((ch == ' ') || (ch == '\t') || (ch == '\n')) { peeker = in.peek(); if((ch == '\n') && (peeker == '\n')) ++paraTotal; if (ch == '\n') ++linesTotal; out << ch; in.get(ch); } return;}////////////////////////////////////////////////////////////////////////////////copyText counts words////////////////////////////////////////////////////////////////////void copyText(ifstream& in, ofstream& out, char& ch, int& w){ if ((ch != ' ') && (ch != '\n') && (ch != '\t')) ++w; while ((ch != ' ') && (ch != '\n') && (ch != '\t') && in) { out << ch; in.get(ch); } return;}/////////////////////////////////////////////////////////////printTotal reports the results of the previous functions///////////////////////////////////////////////////////////void printTotal(int& wordsTotal, int& linesTotal, int& paraTotal, ofstream& y){ y << endl << "Total number of words: " << wordsTotal << "."; y << endl << "Total number of lines: " << linesTotal << "."; y << endl << "Total number of paragraphs: " << paraTotal << "."; return;}
[edited by - Mr McKnowNothing on November 8, 2003 7:17:18 PM] [edited by - Mr McKnowNothing on November 8, 2003 7:18:31 PM]