forked from robotarmy/first_c_challenge
-
Notifications
You must be signed in to change notification settings - Fork 1
anteaya/first_c_challenge
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Please do not share your answers with others - unless it is to ask them questions that guide them to the answers - this is not a memorization excercise. This is an excercise in refining understanding. This program is missing a line - it counts the number of times it sees a lowercase alphabet letter including 'a' and all the way through 'z'. Questions: What does record_init do? The record_init function takes no arguments, set an integer variable, and executes a block which creates a hash called records which is 26 elements long and the first key starts at 97 and increments by 1 and the value for each record is 0. So it creates a hash 26 elements long. It sets up the storage hash for counting the frequency of the occurances of each lowercase letter input. Why is eat_extra_input necessary? It deals with any input after one character upto a newline.The program has to know what to do with this input. How could read_char be implemented differently? The read_char function could accept a string and then split off the first character from that string. -- How would that change eat_extra_input? The eat_extra_input function wouldn't be necessary then since the useful information (the first character) would be returned and the remainder of the string wouldn't have a reference to it. How does C handle garbage collection? Would the rest of the string have to be manually tagged for garbage collection? NEXT PORTION of the ASSIGNMENT When you enter a number at the prompt the program says and assertion is violated - What is this assertion? The assertion is for the ascii value of the first character minus 97 to be greater than or equal to 0 and no greater than 25. This ensures the character is a lower case letter. Why is the assertion violated? The assertion is violated because the ascii value for a number minus 97 does not fall between the range 0 to 25. What are assertions good for? Assertions are good for sanitizing data. What line of code is missing from the program? There is a line missing in the record_char function. After the two assertions have been met, the value in the records hash that corresponds to the key for the letter needs to increment by one. What are all of limitations of this program? One of the limitations is I am uncertain what all of the limitations of this program are. One limitation is the lack of error rescue when the input fails the assertions. Rather than the program quitting, the user should get another opportunity to input data. Another limitation is the frequency of the input letters isn't shown until after the program has been exited. How could this program be extended to support numbers? Both the record_char and the record_init functions would have to accept and create space for character values in the range 48 to 57 in addition to the currently supported range of 97 to 122. How could this program be extended to support chinese characters? Unicode How could this program be extended to support the entire UNICODE character set? Black hole of unicode. Extra ; What is a Makefile It is a file which executes when make is run. Why does 'make' without any arguments compile the code. That is the instructions inside of the Makefile. Why does running 'make' once and then 'make' a second time say 'nothing to be done for `all`'? The compiled file exists. Tips : requires 'GNUMake' and 'GCC' and optionally 'GDB'. compile code: make clean && make run code in debugger: $ gdb first (gdb) run
About
1 line is missing - learn to read C-Code - then answer questions!
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- C 100.0%