Hello and good evening
I'm trying to make a a program that will take text from a input file to a variable in main then use that variable with nested while loops to count all the spaces in the text then display it using cout.
I been at this for hours and I can't figure this out if anyone can please help me I would really appreciate it! Thanks in advance.
#include<iostream>
#include<fstream>
using namespace std;
void processBlanks(int& wrd,char& cp);
int main()
{
ifstream inFile;
ofstream outFile;
int linecount,numpar;
int wrd=0;
char ch;
inFile.open("C:\\Documents and Settings\\Owner\\Desktop\\test1.txt");
outFile.open("C:\\Documents and Settings\\Owner\\Desktop\\output.txt");
if (!inFile)
{
cout<< "can't open File"<<endl;
return 1;
}
inFile.get(ch);
while(inFile)
{
while(inFile&&ch !='\n')
{
processBlanks( wrd, ch);
}
inFile.get(ch);
}
cout<< wrd<<endl;
}
void processBlanks(ifstream& infile, int& wrd,char& cp)
{
if(cp==' ')
wrd++;
return ;
}