- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
CS50x threads to aide as a supplementary resource › 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
#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);
}
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]