Hello everyone,
I am new to C programming, but I will do my best to explain my issues. I am currently taking a course and the assignment that we have right now is to create a word counting program. I am suppose to count the characters, lines, and words in any input. The words need to be able to be counted even if there are more than one space inbetween them (i.e. dog cat is 2 words with 4 spaces in between). I am able to make code that counts the words if there is only ONE space, but how can I code it so that it counts with any amount of spaces?
Below is the current loop that I have that is counting the words.
The idea that I have to go about this issue is to somehow make a temporary variable that reads in the spaces, and when there is a space, it increments the space count. When it reaches a character, it starts to count for a new word. Once it reaches another space, the word count increments. The issue is that I am not sure how I can put this idea into code. Can someone help please?Code:if (isspace(ch) != 0) { wordcount++; }