• Skip to main content
  • Skip to footer

SoftwareProg.com

Software programming learning aide

  • Blog
    • Discussion
  • News
  • CS50’s Introduction to Computer Science by Harvard University on Edx
    • Week 1
    • Week 2
    • Week 3
    • Week 4
    • Week 5

Readability lab: Counting letters

CS50 threads to aide as a supplementary resource › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 2 › Readability lab: Counting letters

Tagged: built-in functions, ctype.h library, isalpha function

  • This topic is empty.
Log In Register Lost Password
Viewing 1 post (of 1 total)
  • Author
    Posts
  • December 30, 2021 at 7:51 am #81
    admin
    Keymaster


      Copy Code
      Copied
      Use a different Browser

      
      
      #include <stdio.h>
      #include <cs50.h>
      #include <ctype.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);
      }

      https://www.canva.com/design/DAEz5-R7Q6g/RE7yde0aEMk7QmZkXhb9Og/view?utm_content=DAEz5-R7Q6g&utm_campaign=designshare&utm_medium=link&utm_source=sharebutton

      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.


      Reply


      https://edstem.org/us/courses/176/discussion/977260?comment=2212677[learn_press_profile]

    • Author
      Posts
    Log In Register Lost Password
    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Log In

    Log in / Register

    Initiative by Digital Splendid OPC Pvt. Ltd.