Join 132,304 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,047 people online right now. Registration is fast and FREE... Join Now!
This program is supposed to count the number of words, characters, and lines in a text file and then output the contents of the file to the display. It seems to work correctly, except it comes up with the wrong number of words and lines. The file I am testing it with looks like this:
this is a simple file [indent]with
some data
There are 40 characters, including spaces, tabs, /n, and text, 5 lines, and 8 words. When I run my program, it always counts 1 line, 6 words, and 41 characters. I just can't seem to figure out what is going on. Any help would be greatly appreciated.
CODE
#include <iostream> #include <fstream>
using namespace std;
int algorithm(void); int code(string); void initialize(int& words, int& letters, int& lines); void readBlanks(char& ch, int& wrdCount, int& chCount, ifstream& file); void copyChar(char& ch, int& chCount, ifstream& file); void display(int wrdCount, int chCount, int lineCount);
int main() {
ifstream inFile; int words, lines, letters; char next; int result;
This program is supposed to count the number of words, characters, and lines in a text file and then output the contents of the file to the display. It seems to work correctly, except it comes up with the wrong number of words and lines. The file I am testing it with looks like this:
this is a simple file [indent]with
some data
There are 40 characters, including spaces, tabs, /n, and text, 5 lines, and 8 words. When I run my program, it always counts 1 line, 6 words, and 41 characters. I just can't seem to figure out what is going on. Any help would be greatly appreciated.
CODE
#include <iostream> #include <fstream>
using namespace std;
int algorithm(void); int code(string); void initialize(int& words, int& letters, int& lines); void readBlanks(char& ch, int& wrdCount, int& chCount, ifstream& file); void copyChar(char& ch, int& chCount, ifstream& file); void display(int wrdCount, int chCount, int lineCount);
int main() {
ifstream inFile; int words, lines, letters; char next; int result;
This program is supposed to count the number of words, characters, and lines in a text file and then output the contents of the file to the display. It seems to work correctly, except it comes up with the wrong number of words and lines. The file I am testing it with looks like this:
this is a simple file [indent]with
some data
There are 40 characters, including spaces, tabs, /n, and text, 5 lines, and 8 words. When I run my program, it always counts 1 line, 6 words, and 41 characters. I just can't seem to figure out what is going on. Any help would be greatly appreciated.
CODE
#include <iostream> #include <fstream>
using namespace std;
int algorithm(void); int code(string); void initialize(int& words, int& letters, int& lines); void readBlanks(char& ch, int& wrdCount, int& chCount, ifstream& file); void copyChar(char& ch, int& chCount, ifstream& file); void display(int wrdCount, int chCount, int lineCount);
int main() {
ifstream inFile; int words, lines, letters; char next; int result;
Anyway, since my code is already here, should I have done anything differently? I mean, there must be many ways to do this type of thing, many of which are probably easier than my approach. Any tips or pointers?