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 › Scrabble problem: Uppercase and lowercase letters
Tagged: arrays, ASCII, ASCII codes, builtin functions, c, islower, isupper, library functions, lowercase, lowercase letters, scrabble lab problem, string.h, strlen, toupper, uppercase, uppercase letters
- This topic is empty.
-
AuthorPosts
-
November 19, 2021 at 7:19 am #56
Working on Week 2, Scrabble Lab 2.
[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”]
int compute_score(string word) { int n = strlen(word); char temp_upper; int score = 0; for(int i = 0; i< n; i++) { temp_upper = toupper(word[i]); int point_index = temp_upper - 65; score = score + POINTS[point_index]; } return score; }
[/dm_code_snippet]
Source: https://github.com/volkansahn/CS50-Fall2020/blob/master/Week2/Lab2/scrabble.c
I know referring blindly to answer might not be acceptable but doing so for the sake of understanding.
Here are few of the things that I need to make clear:
1. Is strlen an inbuilt function with used libraries (string.h/ctype.h) that computes length of a string?
2. temp_upper = toupper(word[i]); Does this command converts all entered letters to uppercase letters?
3. int point_index = temp_upper – 65; All letters are converted to smallcase letters so that POINTS array can be applied?
Reply
https://edstem.org/us/courses/176/discussion/874392?answer=1997454[learn_press_profile]
-
AuthorPosts
- You must be logged in to reply to this topic.