Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int fnWords(const char *sentence) {
  5.     int iCount = 0, i, iLen;
  6.     char lastC;
  7.     iLen = strlen(sentence);
  8.     if(iLen > 0) {
  9.         lastC = sentence[0];
  10.     }
  11.     for(i = 0 ; i <= iLen ; i++) {
  12.         if((sentence[i] == ' ' || sentence[i] == '\0') && lastC != ' ') {
  13.             iCount++;
  14.         }
  15.         lastC = sentence[i];
  16.     }
  17.     return iCount;
  18. }
  19.  
  20. int main() {
  21.     const char *string = "Please, write the following message: !!!Error!!!Program will be terminated! ";
  22.     printf("Words = %i\n", fnWords(string));
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement