fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void) {
  5. char text[500];
  6. int count = 0;
  7.  
  8. printf("Enter text:\n");
  9. fgets(text, sizeof(text), stdin);
  10.  
  11. char *token = strtok(text, " \n\t");
  12. while (token != NULL) {
  13. count++;
  14. token = strtok(NULL, " \n\t");
  15. }
  16.  
  17. printf("Total number of words: %d\n", count);
  18. return 0;
  19. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Enter text:
Total number of words: 1