Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int fnWords(const char *sentence) {
- int iCount = 0, i, iLen;
- char lastC;
- iLen = strlen(sentence);
- if(iLen > 0) {
- lastC = sentence[0];
- }
- for(i = 0 ; i <= iLen ; i++) {
- if((sentence[i] == ' ' || sentence[i] == '\0') && lastC != ' ') {
- iCount++;
- }
- lastC = sentence[i];
- }
- return iCount;
- }
- int main() {
- const char *string = "Please, write the following message: !!!Error!!!Program will be terminated! ";
- printf("Words = %i\n", fnWords(string));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement