Year #3, Week #8 đ» đ„
New stuff we learned this week:
C Strings
- strings in C are essentially arrays of
char
s with anull
byte at the end, like this:
char hello[] = {'H', 'e', 'l', 'l', 'o', '\0'};
- You can also express a string using a string literal. The below is the same as above:
char* hello = "Hello";
<string.h>
has the functionstrlen()
which takes achar *
and will return the length of a string without the null byte.<stdlib.h>
has a functionatoi
which takes a string like"72"
and returns an integer72
.
C: Argv/Argc
- Until now, weâve been writing our
main
function using the signature:
int main(void) {
}
- But C programs can also receive command line arguments, with the following
signature, where
int argc
is the count of the arguments, andchar *argv[]
is an array of strings:
int main(int argc, char *argv[]) {
}
Homework Plan
- 1 day Monkey Assignment #16 đ
- 1 day review all flashcards in your app.
- 1 day touch typing practice
- 1 day CS50 âCaeserâ assignment
- 1 day CS50 âReadabilityâ assignment
- 1 day Snowpack assignment đ
- 1 day Flashcards Webapp assignment
- 1 day watch Lecture 2 of
CS50, from
1:06:00
to end. - 3 days Execute Program homework
CS50 Caeser Assignmnent
- Slowly and carefully read the âNew Stuffâ above â I put one thing in there that we did not cover in class that will be useful for this assignment.
- Make sure youâve watched the CS50 video before starting.
- Make sure your branch from last CS50 Assignment (Mario, Credit) is merged (after addressing any feedback outstanding).
- Create a new branch named
caeser
- Read and complete the Caeser Assignment detailed here. (Note: this link wonât work unless youâre using Safari, because of Gertrude) Take it bit by bit, as they coach you to do, starting by handling the number of command line arguments, then validating the key, etc.
- You should use
get_string()
to read in the âplaintextâ from the user. You can use the fakestring
type, orchar *
, whatever you want. - When you think youâve got it done, re-read the Specification section,
and make sure you meet all of the criteria. Especially double-check little
details and edge cases like:
- returning a non-zero exit code when an error
- printing the
Usage: ./caeser key
when wrong number of argument supplied, or if any non number characters supplied. - make sure you handle keys larger than 26 properly
- double-check that uppercase letters stay uppercase, and lowercase lowercase.
- make sure non-letter values remain untouched.
- when your program is complete, submit a MR, then review your diffs and clean up your code, then slack me the URL.
CS50 Readability Assignmnent
- Make sure youâve completed the Caeser assignment first (although itâs OK if it hasnât been reviewed or merged yet).
- Make a new branch off of master called
readability
. Donât put this work on the same branch as your âCaeserâ assignment. - Re-read the last step and actually do it! Harriet, Willow, Iâm looking at you!
- Read this complete assignment until the end before starting.
- Read and complete the
Readability assignment detailed here,
with the following hints/requirements:
- hard-code one or two sentences to test and build your program. Only when you
have everything working go back and replace the hardcoded user input with a
prompt to
get_string()
. - your hardcoded test data should be typed as either a
string
orchar *
(which are the same thing), and can be expressed in C with string literals, like:char* input = "It was a bright and cold day in April...";
- Donât use
getchar
anywhere - remember there are some useful string-related functions in
<string.h>
includingstrlen
. - Work through the task in the baby-steps outlined in the assignments â namely, start by counting (and temporarily printing) the number of letters. Then count the words, then the sentences. Only when you have that all done do you plug it into the formula.
- hard-code one or two sentences to test and build your program. Only when you
have everything working go back and replace the hardcoded user input with a
prompt to
- When you think youâre done, plug in all of the test examples in the
âHow to test your codeâ section at the bottom of the page. Make sure you
get the right answers (including exactly
Grade 16+
) for the last one. Fix your code if you get the wrong answers to anything. - when your program is complete, submit a MR, then review your diffs and clean up your code, then slack me the URL.
Monkey #16
- Address all feedback from prior MRâs, and merge.
- Create a new branch.
- Double-check that you did the first two steps.
- Triple-check that you did the first three steps.
- Start at section 2.8 - Function Literals. Work through that section, and commit your work when you finish.
- As always, make sure to try to do as much as you can without the videos, but always also watch the videos and update your code to (mostly) match.
- Video link
- Submit a MR, Review your diffs and fixup!!, then slack the MR url
Snowpack Assignment đ
- Read the following page of the Snowpack docs site: https://www.snowpack.dev/concepts/how-snowpack-works
- SSH into the HTC pi, and create a temporary directory somewhere that youâll delete later.
- in that directory, follow all of the steps of the Getting Started tutorial.
- after you finish, also do the following steps:
- use
ls
to inspect what snowpack put in your âbuildâ dir. Do you understand the files it output somewhat? - switch your javascript files (both
index.js
andhello-world.js
) to be TypeScript. Make sure the project still works in dev mode and builds correctly. If itâs not working, search the docs site for help. - Next, figure out how to change it so your build command outputs the built
files in a folder called âpublicâ instead of âbuildâ. (Hint: youâll have to
configure snowpack, which is done using the
snowpack.config.js
file â there is a page on the docs site dedicated to all of the options available.) - Finally, find the page on the snowpack site that describes how to install Tailwindcss. Follow all of the steps carefully, until you have Tailwindcss working in your tutorial site.
- When you have it working add a couple of tailwind classes to some of the HTML youâre rendering, then take a screenshot of your code together with the web page, so that I can see the tailwind styles taking effect, and also Iâd like to see the confetti as well. Slack the screenshot.
Flashcards Web App Assignment
- Make sure youâve fully completed the âSnowpack Assignmentâ first.
- Now that you have a basic understanding of how to use Snowpack + Tailwind +
Typescript, I want you to create a brand new repository for your flashcards
web-app (version 2.0). But instead of having you set it up from scratch, Iâm
going to have you pull down and use a boilerplate I created. You already know
90% of whatâs in the boilerplate now that youâve completed Part I of this
assignment, so nothing in it should be confusing. The main advantage to the
boilerplate is that I did some fiddly work so that the source files can be in
a
src/
directory (instead of the project root), and I added some extra plugins for fast dev and environment variables. - SSH into the HTC pi and then check out the readme for my boilerplate here.
- Follow the instructions, EXCEPT for donât use the folder name
my-rad-project
â pick a folder name that you want to use. - (đ€ Aside:
git clone
by default creates a folder with the same name as the end of the git url. So if you rungit clone git@github.com:goat-banjo-rodeo
then youâll get a folder calledgoat-banjo-rodeo
. But, if you want your folder named something else, you can pass the name of your desired destination directory last, likegit clone git@github.com:goat-banjo-rodeo secret-project
. If you do that,git
will clone into a dir calledsecret-project
. Take a minute and figure out where in my instructions Iâm using that technique.) - If you followed the instructions fully, you shoud have blown away your
.git/
dir that you got from cloning. Initialize a new git repo, and hook it up to a brand new repo on GitLab named however you like. - Commit all of the âworkâ so far â really this is just commiting the files from the boilerplate. But we want to commit and push at this point so I can see the changes you make, that are coming next.
- Push up your initial commit to the
master
branch. - Make and check out a new branch.
- If your name is Harriet or Willow, double-check that you did the last step. If you forget, you have to bake me some cookies. đ©âđł
- Fire up the dev server and make a few changes to the
App.tsx
file. Enjoy the blazing speed of unbundled development, thanks to ESM, Snowpack, and Fred Schott. - Run the build command once. Where did it spit the built files? Delete the built files when youâre done inspecting them.
- Modify the package.json build command so that it spits out your built
website into your
$USER/www
dir. Use what you learned in the Snowpack assignment. If you need to, check your personal project or your old flashcards app for a clue how to specify the path to the built dir. - For your last step, I want you to install and integrate the StoryLite package I demonstrated in class. Instructions can be found here. Make at least one âstoryâ with a proof-of-concept, hello-world component. Donât spend any time on the component itself, weâre going to throw it away in the coming weekâs assignment. But use to make sure you can get StoryLite rendering.
- Be sure you set up your root
App
component so that it switches back and forth between displaying your app, and displaying StoryLite, using the query param?storylite=1
in the URL. - When youâve got it working, experiment briefly with going into StoryLiteâs âfullscreenâ mode, and also closing out of StoryLite with the âxâ button.
- Take a screenshot of your StoryLite âstoryâ, and either slack it with your MR url, or include it in the MR description.
- Commit your work, push up a MR.
- Review your diffs, clean up anything you notice, then slack me the URL.