• This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #709
    admin
    Keymaster
      
      
      #include <stdio.h>
      #include <cs50.h>
      #include <string.h>
      #include <ctype.h>
      
      int lettercounter(string enteredword);
      int wordcounter(string enteredword);
      
      int main(void) {
          string enteredword = get_string("enter word:");
          int y = lettercounter(enteredword);
          printf("number of alphabetical characters: %i\n", y);
      
          int f = wordcounter(enteredword);
          printf("number of words: %i\n", f);
      }
      
      int lettercounter(string enteredword) {
          int t = strlen(enteredword);
          int x = 0;
          int c = 0;
          for (x = 0; x < t; x++) {
              if (isalpha(enteredword[x])) {
                  c = c + 1;
              }
          }
          return c;
      }
      
      int wordcounter(string enteredword) {
          int t = 0;
          int c = 1;
          int x = strlen(enteredword);
          for (t = 0; t < x; t++) {
              if (enteredword[t] == ' ' || enteredword[t] == '!' || enteredword[t] == '?') {
                  c = c + 1;
              }
      
          }
          return c;
      
      }

      readability lab

      Counting number of sentences is almost similar to counting number of words with only one difference:

      
      
      if (enteredword[t] == ' ' || enteredword[t] == '!' || enteredword[t] == '?')

      Instead of:

      
      
       if (enteredword[t] == ' ' || enteredword[t] == '!' || enteredword[t] == '?')

       

      
      
      #include <stdio.h>
      #include <cs50.h>
      #include <ctype.h>
      #include <string.h>
      int lettercounter(string enteredword);
      int wordcounter(string enteredword);
      int sentencecounter(string enteredword);
      int main(void)
      {
          string enteredword = get_string("enter word:"); int y = lettercounter(enteredword);
          printf("number of alphabetical characters: %i\n", y);
          int f = wordcounter(enteredword);
          printf("number of words: %i\n", f);
          int s = sentencecounter(enteredword);
          printf("number of sentences: %i\n",s);
      }
      
      
      int lettercounter(string enteredword)
      {
      int t = strlen(enteredword);
      int x = 0;
      int c = 0;
          for (x = 0; x < t; x++)
          {
              if (isalpha(enteredword[x]))
              {
              c = c + 1;
              }
      
          }
      return c;
      }
      
      
      int wordcounter(string enteredword)
      {
      int t = 0;
      int c = 1;
      int x = strlen(enteredword);
          for (t = 0; t < x; t++)
          {
              if (enteredword[t] == ' ' || enteredword[t] == '!' || enteredword[t] == '?')
              {
              c = c + 1;
              }
      
          }
      return c;
      }
      
      
      
      int sentencecounter(string enteredword)
      {
      int s = 0;
      int x = strlen(enteredword);
      int c = 0;
          for (s = 0; s < x; s++)
          {
              if(enteredword == '.' || enteredword == '!'  || enteredword == '?')
              {
              c = c + 1;
              }
          }
      return c;
      }

      cs50

       [learn_press_profile]

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