Write a c program where the number of characters in each


Problem

Write a C++ program where the number of characters in each word of a text file is counted. I'm having trouble defining in my loop exactly when a word begins and ends (using characters). How can I reword this loop so that it recognizes a word and adds the number of characters in it to the variable called "word?" Here's what I have so far:

#include
#include
#include
using namespace std;
int main(){
ifstream fin("file.txt");
int word=0;
char ch;
while(fin && ch!= '.'){
if(ch==' ' || ch=='\n')
word++;

//It is wrong because the end of text may have large portions of blank spaces which, by this loop, would be counted as chars in a word.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write a c program where the number of characters in each
Reference No:- TGS02780525

Expected delivery within 24 Hours