Lab 1
1. Setup (2 mins)
- Labs are a co-operative time! Introduce yourself to someone!
- You can work individually or in pairs (pair-programming).
- Help others!
- Use either your own laptop or the lab PC.
- Only if using CSIL lab PC:
- [Only CSIL PC] If in Windows, reboot to Linux.
- While booting, select Ubuntu from boot menu.
- [Only CSIL PC] Don't setup GitHub tokens in container because it may be shared with other users.
- [Only CSIL PC] Delete any possible previous docker container:
docker rm cmpt201
- [Only CSIL PC] If in Windows, reboot to Linux.
- Launch the docker container.
- See Resources page for commands.
- You do not need to use
.record
2. Design (10 mins)
Your task is:
Write a program that receives a user input, tokenizes it with the delimiter " " (space), and prints out each token one at a time on a new line. Use
getline()
for user input andstrtok_r()
for tokenization.
Example output:
Please enter some text: Tomorrow is Friday. Tokens: Tomorrow is Friday.
- Design your solution.
- Don't Google it; you need these skills. Labs are for figuring it out, not for completing work.
- Use man pages for
gitline()
andstrtok_r()
. - Discuss to your partner, or someone else, how each of these functions works.
- Note that
strtok_r()
uses a**
(a pointer to a pointer).- Think why it uses a pointer to a pointer.
- Think what you'll need to pass in, and what will it give you back.
- Try drawing a picture.
- Suggestion: use pseudo code to plan your code.
3. Implement it! (20 mins)
- Write a couple lines of code then compile, run, debug. Repeat!
- Do simplest thing first (hint
"Hello world!"
). Then add functionality bit-by-bit.
4. Reviewing (10 mins)
- During the last 10 minutes, TAs will show a sample solution.
- TAs will talk through how the solution works and discuss its implementation.
Nothing is submitted for this lab. Thank you for learning!
If you were working on a CSIL machine, delete your docker container:
docker rm cmpt201