CS 240 TA Notes

Lab 6

1. Problem 2: There is a bug in the original instructions. Please change the function prototype as below:
int setsleepinterval(char *, int **)

2. Problem 2: For the command line mode, the instructions say "the last command-line argument is interpreted as a string that serves as a reminder message."
Please note that "the last command-line argument" can be multiple "last command-line arguments."
Meaning, if we run the program like remindapp 10 5 3 take a break , the reminder string should be "take a break", not "break".

3. Problem 2: For the interactive mode, I will provide several examples of the input message for better understanding of the input specs.
This is a valid remindrequest input: 10 20 3 take a break
This is not a valid remindrequest input: 010 020 03 take a break
This is not a valid remindrequest input: 0 1 2 take a break
This is not a valid remindrequest input: 10f 4 2s take a break

Lab 5

1. Important Announcement: Please name your global variable names, files, executables, and output files as the instructions say!
It is crucial, and it is your responsibility as a programmer, to submit a program that runs as expected with our test cases.

2. Problem 4: Consider the following ASCII characters from the instructions: aaA2!3AA
ASCII character 'A' has a decimal value of 65, so resu.count[65] will store the number of its occurrences, which is 3.
Similarly, resu.count['3'] or resu.count[51] will store 1.
Note that indexing should be done as i being the i'th ASCII character for the ASCII character in range of 0 <= i < 128.

Lab 4

1. Problem 1: There was a typo in the original instruction. It has now been updated, but make sure your outputfilename takes a char pointer as an input argument. Your function prototype should look like this: void outputfilename(char*)

2. Problem 2: For clarification, each line in an input file except for the last line should end with a '\n'.
When implementing numlines() function, please make sure that it returns the number of '\n' characters plus 1 for the last line.

Lab 3

1. Problem 5: There is a bug in the original instruction for this problem. Please change the function prototype as below:
int readlines(char filelines[][MAXCOL])
int reorder(char filelines[][MAXCOL])

Lab 2

1. Problem 12: Please note that there is a typo in the instruction. It says "1-D integer array, x[5]." This is referring to the variable y[5] in the sample code.

2. Problem 11: For anyone who's curious about how the stack smashing detection works...
Recall that when a function is being called, the return address back to the callee is placed between the caller and callee's stack frames.
At the beginning of a function call, a known value (canary) is placed onto the stack below the return address.
Before the function returns, the canary value is checked.
When a buffer overflow happens, it will typically overwrite local variables and then the canary value, and thus, changing the canary value.
So in this way, a stack smashing can be detected detected when the canary value becomes altered.

Lab 1

1. If you want to work from home, you can do ssh your_purdue_login@borg{number}.cs.purdue.edu
We will use Linux PCs in HAAS G040 (borg), and you should compile, debug, and evaluate your code from these borg machines.

2. You can edit your own vim setting to match with your preferences.
Do vim ~/.vimrc and add whatever settings you want to add into here.
For example, I have set number to display line numbers on the left side, and set tabstop=2 and set shiftwidth=2 to set tabs to be 2 spaces wide.

3. One way to write to submit your written answers as a pdf file is to first write everything in a txt file in your working directory then export it as a pdf.
You can use these command lines to export txt to pdf.
enscript -p lab1.ps lab1.txt
ps2pdf lab1.ps lab1.pdf

Update: You can also run the following command from your local machine to securely copy files to the server.
scp /path/to/local/file username@data.cs.purdue.edu:/path/to/remote/directory/

4. Problem 7 Hint: When you run the program with a different return value, and it prints out the string "result of ..." properly, does it mean the program ran normally?
You can try returning -1 as the instruction says and observe what happens!
More Hint: You can check whether the program ran normally or abnormally by checking its exit status. In bash, $? stores the exit status of the last command. Look up how to print this on your terminal!