while loops and stuff

Hey everyone I'm working on a project for a class. I'm supposed to take a text file, open it, print it, and reopen it replacing every fifth word with a series of blanks. I can get the file to open and print the first time but after that, I am stuck.Heres the code I have so far.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
#include <cctype>
using namespace std;

int main ()
{
	char ch;
	char fileName [20];
	bool lastWasLetter = false;
	bool thisLetter = false;
	const string BLANKS = " __________ ";
	int  wordCount = 0;
	ifstream inFile;
	
	cout << "Give file name:" << endl;
	cin >> fileName; 

	inFile.open (fileName);
	inFile.get (ch);


	while (!inFile)
	{
		inFile.clear ();
		cout << "File name invalid. Please re-enter the file name:" << endl;
		cin >> fileName;

		inFile.open (fileName);
		inFile.get (ch);
	}

	cout << ch;
	while (inFile) 
	{
		inFile.get (ch);
		cout << ch;
	}
	
	inFile.clear ();
	 inFile.seekg(0L, ios::beg);


That's the part that works. I'm working on just making it show the file again first, then worrying about counting the words and replacing them. I can't figure out how to do it thought. Any help is welcome
To start, see if you can just print the file word by word, rather than line by line. Then it should be easy to replace every 5th word with blanks.

How will you get every 5th word?
Topic archived. No new replies allowed.