i am trying to write a function word(istream&, char*)that counts the words from the input file.
how to proceed? p lease suggest anybody.
This is a discussion on c++ within the C++ Programming forums, part of the General Programming Boards category; i am trying to write a function word(istream&, char*)that counts the words from the input file. how to proceed? p ...
i am trying to write a function word(istream&, char*)that counts the words from the input file.
how to proceed? p lease suggest anybody.
I suggest finding your textbook. Open at the relevent page and then read. Might work. If not, post some code.
1. Check every character of the input stream one after the other.
2. If any of the characters is " " (space) and the next one is not " " space...increment the variable 'words' by 1.
e.g.
for (int i=0;i!=(total_file_size_in_bytes);i++)
if (letter[i] == ' ' && letter[i+1] != ' ')
wordcount++;