C++

C++ Program to Count Number of Words in a Sentence1 min read

C ++ tutorial aims to count the number of words in a C language sentence under Code Blocks software.

To write this program we will need a single function with 4 variables: i a counter that will count the number of words, ph an integer to know if we have entered the sentence or not and n to count word by word and a character c to detect the point “.”




First we need a loop “while” to take into account that the sentence will be at least one word, after we will have a condition on the space that will be between the words so that it does not count as being a word.

Simple program to be able to count all the words in a text for example, that will avoid the risk of being mistaken and forget some if they are counted manually.

 

 

Leave a Comment