• This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #126
    admin
    Keymaster
      
      
      #include <stdio.h>
      #include <cs50.h>
      #include <string.h>
      
      int main(void) {
          string enterword = get_string("input: ");
          int t = strlen(enterword);
          printf("%i\n", t);
          int counter = 0;
          for (int i = 0; i <= t; i++) {
      
              if (enterword == '.' || enterword == '!' || enterword == '?') {
                  counter = counter + 1;
              }
          }
          printf("number of lines %i\n", counter);
          int wordcounter = 1;
          for (int i = 0; i <= t; i++) {
              if (enterword == ' ') {
                  wordcounter = wordcounter + 1;
      
              }
          }
          printf("total words %i\n", wordcounter);
      }

      After getting counted the number of words, sentences, it is time to count number of letters. Here is my tentative idea:

      lettercounter = 0

      Total characters are known by string length function.

      lettercounter will be lettercounter = lettercounter + 1 whenever there are alphabets till it reaches string length. Now, one point to clear is how alphabets will be distinguished from digits, punctuation marks. Is my approach correct?


      Reply


      https://cs50.stackexchange.com/questions/42285/readability-lab-counting-letters[learn_press_profile]

    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Scroll to Top