IT, Programming, & Web Development › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 2: [Arrays] – Functions, Variable and Scope, Debugging, Arrays, and Command Line Arguments › Readability lab: Counting letters
- This topic is empty.
-
AuthorPosts
-
December 30, 2021 at 7:51 am #81
[dm_code_snippet background=”yes” background-mobile=”no” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
#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[i] == '.'|| enterword[i] == '!' || enterword[i] == '?'){ counter = counter + 1;} } printf("number of lines %i\n",counter); int wordcounter = 1; for (int i = 0; i<= t; i++) { if (enterword[i] == ' ' ){ wordcounter = wordcounter + 1; } } printf("total words %i\n", wordcounter); }
[/dm_code_snippet]
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]
-
AuthorPosts
- You must be logged in to reply to this topic.