fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main() {
  4. char str[100];
  5. int words = 0, chars = 0;
  6. fgets(str, 100, stdin);
  7. for (int i = 0; i < strlen(str); i++) {
  8. if (str[i] != ' ' && str[i] != '\n') {
  9. chars++;
  10. }
  11. if (str[i] == ' ' || str[i] == '\n') {
  12. words++;
  13. }
  14. }
  15. if (chars > 0) words++;
  16. printf("Words: %d, Characters: %d\n", words, chars);
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Words: 0, Characters: 0