I've been working on this for a couple of hours now, rereading the textbook and tutorials to try to help, and I can't seem to graps this section (though I am proud that I got other looping aspects down). I think the problem with this one is I also have to use a file that already contains data.
The program I need to design reads data from an input file and counts all of the 3, 4, 5, and 6 letter words within the file. It then takes the count information and outputs it to another file. I know the program needs to loop four times, the first searching and counting all 3 letter words, etc. The problem is, the more I write the code, the more frustrated I become. Here is the code I have so far, complete with errors.
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
ifstream inFile;
ofstream outFile;
int count ;
int charCount ;
int count3 ;
int count4 ;
int count5 ;
int count6 ;
char inChar ;
inFile.open ("QUOTES.TXT") ; //The file to be read.
outFile.open ("NUMWORDS.TXT") ; //The file that will be created with the count information.
The problem is, how do I write the code to read the characters in the file and count the 3, 4, 5, and 6 letter words? I've been at it for a few hours and even slept on it to try to clear my head. I can't wrap my brain around this one. Thanks for any and all help.
That creates the output file, and it also compiles correctly, but the program doesn't count the words in the input file. If I identify counts 3, 4, 5, and 6 to be equal to 1, then the program outputs them as 1 without counting anything. If I don't identify them, then it errors when I run the program and outputs the counts as a large negative number.
I tried it in my program, and it's yielding a blank document. I'm not sure what I'm doing wrong. It compiles correctly, but the command screen doesn't say anything, and the output file is empty when I open it. It doesn't even give me false numbers.
I have a feeling that my computer is jacked up. This isn't the first time I've experienced problems. I will work on this at the school's computers and see what happens. Thanks again for all of the help everyone.
And yeah, I have a QUOTES.txt. The last program posted will compile and display the else information, but I can't get it to put anything in the numwords file. Why do I always have trouble with reading from data files? :P
The programs dealing with For statements that I had to do last week were easy as pie. *sigh*
#include <iostream>// for cout, endl
#include <iomanip>// for setw() and setprecision()
#include <fstream>// for ifstream and iostream
#include <string>
using namespace std;
int main ()
{
ifstream inData;
ofstream outData;
int count1;
int count3 = 0;
int count4 = 0;
int count5 = 0;
int count6 = 0;
char inChar;
Sorry, I didn't know you were using my code as posted. Where is your QUOTES.txt file located? I removed the path before posting the code. The code will run as posted but if your QUOTES.txt file if not in the same Dir as the .cpp file it will just give you a blank NUMWORDS.TXT file.
My quotes file is in the same directory. I'm going to try it at school tomorrow. Failing that, I will go to the instructor, though I don't learn anything from him.