Advertisement
boyan16-z

The number of words (strings)

Mar 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.33 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7. char str[255];
  8. int count = 0, i;
  9. printf("Insert: ");
  10. gets_s(str);
  11. for (i = 0; i < strlen(str) - 1; i++)
  12. if ((str[i] == ' ') && (str[i + 1] != ' '))
  13. count++;
  14. if (str[0] != ' ') count++;
  15. printf("\nConclusion: %d\n", count);
  16.  
  17. return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement