CIS2500 Lab Two
There are no tasks or coding lessons this week, we just want to make sure that you have gotten on board with Git and are comfortable with the core concepts required to complete your first assignment.
Agenda
- Moodle Survey
- Git
- Review
- Parsing
- A1 Advice
Moodle Survey
Before we begin, Justin wants everyone to take a moment to fill out his survey on Moodle.
GIT Setup
Setup Your Profile
Execute the following commands. The ‘user.name’ and ‘user.email’ parts aren’t placeholders for anything and meant to be entered as shown. The parts between brackets are placeholders and should be replaced with your credentials, omitting the brackets when doing so.
git config --global user.name <usernameHere>
git config --global user.email <emailHere>
Login Credentials
- Your Git Username is the same as your SSO login
- Your Git password is your SOCS password
- This is (likely) different than your SSO password
- Default is your 7 digit student number
- Can change using
passwd
after SSHing into a UofG server (assuming you know your old password to login) - Alternatively, by visiting the Forgotten Password Page
Basic Commands (Minimum Needed to Submit Assignment)
git clone
- Downloads a repository from a server
- Only done to initially retrieve a repository (use
pull
to update) - Often can be done w/o any sort of login credentials (ie. public Github repos)
git add
- You need to add files before they will be tracked by Git
- Adding a directory will add its contents recursively
git commit -m
- Logs changes which you have made and takes a snapshot of the work you have done (to tracked files)
git push
- Uploads commits to the remote server
Other Helpful Commands
git pull
- Downloads any commits added since your last clone or commit
git status
- See an overview of changes since your last commit/ clone
- Useful to verify which files are going to be included/ omitted
git log
- See an overview of commits you have made
git checkout
- Switch your ‘snapshot’ to another one
git rm
- ‘Untracks’ a file
- Will actually
rm
the file too so be careful - Use
rm --cached
if you want to keep your file but just remove it from git if you added it accidentally
Review
Getting arguments in from the command line using argc
and argv
- Recall that for both
argc
andargv
, your program name itself is always considered the first argument - Recall that
argc
is the argument counter- your program name itself will increment the counter by 1
- …so if you where to pass one argument to your program,
argc
would be 2
- Recall that
argv
is a 2D char array which holds the strings which themselves- Like all arrays in C, their index begins with 0
- …so your program name is contained in
argv[0]
- …so if you where to pass one argument to your program,
argv[1]
would be it
Opening files
- Recall that we use
fopen
to open a file - Always check to ensure that your file was able to be open
- Always remember to use
fclose
to close your file when you are done accessing it
Reading lines from a file
- Recall how to use
fgets
to read in a line from a file.
Parsing
strtok: A Blessing and a Curse
strtok
is useful for parsing strings within a loop. It has some caveats to take into consideration though. You by no means need to use it for this assignment, however it may be helpful to know.
char* strtok(char* str, char* sep);
str
is the string that you want to parsesep
is a list of the delimiter that you want to use- Returns a
char*
token; the substring between either the start of your string/\0
and the next eliminator or newline/EOF/\0
.- Does not allocate memory for you so there is no need to free this reference (if you don’t know what this means yet thats okay, disregard)
- Works by replacing the delimiter in your string with nul terminators (
\0
)- Is destructive; modifies your passed string
- on subsequent calls to
strtok
, passNULL
as thestr
argument to continue where you left off- Keeps an internal static reference of where you where last
- Cleared when you switch strings
Other Possible Topics of Interest
- How to read in a char at a time file from a file stream
- man
getc
- Returns an int, which cat be treated like a char
- Returns
EOF
at the end of file - Note that
EOF
is not actually a character
- man
- Know when we’re done reading from a file
- man
feof
- Useful when looping with
fgets
- man
Advice for A1 and Beyond
Stay for my office hours after the lab to discuss specific concerns and strategies. In general, keep the following in mind when coding:
- Have a game plan before you start
- Be prepared to take another approach
- Strive for elegance, not cleverness
- Refer to the requirements (frequently)
- Don’t treat testing and debugging as an afterthought