What we will cover today
- Exercise 3: review
- Some Recommendations
- Frequently Asked Questions
- Common Pitfalls in C
Exercise 3 review
- some quite nice solutions
- some complaints
- deadline extended by one week
- re-submit incomplete solutions
Some Recommendations
- teamwork works better
- share code
- divide code into modules
- don't program on Windows
- hand in even incomplete code
- document your code
Frequently Asked Questions
- What do I have to do to get the certificate?
Hand in solutions to all (but one) exercise sheets. Ideally your solutions should fulfil all tasks listed in the exercise sheet.
- Will the difficulty level of the exercises change?
They will get easier over time. This is due to three reasons:
You will learn C, you will work in groups, and the exercises will be scaled down as there are probably enough other things you have to do at the end of the semester.
- What about group work?
You will hand in solutions as groups from December on.
Currently, teamwork is recommended and probably needed. You just have to hand in a solution by yourself.
C pitfalls [1]
Windows C vs. Linux C.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char *colour;
int main(int argc, char *argv[]){
scanf("%s",&colour);
if (strcmp(colour,"blue")){
printf("DATE:"__DATE__);
}
}
C pitfalls [2]
Flexible Arrays
int main(int argc, char** argv) {
int numcolors;
char* colors[numcolors];
if(argc == 2) { // if argument given
// init colors
numcolors = 3;
colors[0] = "red";
colors[1] = "green";
colors[2] = "blue";
}
}
C pitfalls [3]
String Comparison
#include <stdio.h>
int main(int args, char** argv) {
char* string = "..."
if (argv[1] == "blue") {
printf("\033[34;1m");
printf(string);
} else if (argv[1] == "green") {
printf("\033[42;1m");
printf(string);
} else if (argv[1] == "red") {
printf("\033[31;1m");
printf(string);
}
printf("\033[0");
return 0;
}