Confused on Readability, Week 2 #2
-
int count_letters(string text)
{
int total_letters = 0;
for (int i = 0; i < strlen(text); i++) // for amount of characters inside string_text, also add it to i for the amount of characters
{
if ((text[i] >= 97 && text[i] <= 122) || (text[i] >= 65 && text[i] <= 90)) // if amount of characters (i) is more than or equals 97 and less than or equals 122. Also if amount of characters (i) is more than or equals 65, and less than or equal to 90
{
total_letters++; // add to total letters for every instance of this occuring
}
}
return total_letters;
} I tried this problem for a while but ran into a roadblock when dealing with arrays so I wanted to see how you would do it. I'm having difficulty understanding the purpose of the numbers, 97, 122, 65 and 90. Where did you get those from? Why do you need those? I'm also confused on why you never add the function count_words to your function args as the assignment says,
for instances of 100 string words in array text i++
} Oh, I see why you didn't specify what a letter is, as of writing this I realized.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Those letters are the ASCII values of the symbols. 97 is lowercase a, 122 is z, 65 is A, and 90 is Z. https://www.asciitable.com/ |
Beta Was this translation helpful? Give feedback.
-
@LimesKey could you please send me an invite link to the Discord server? Thanks! |
Beta Was this translation helpful? Give feedback.
Those letters are the ASCII values of the symbols. 97 is lowercase a, 122 is z, 65 is A, and 90 is Z. https://www.asciitable.com/