Review problems 2#
Activity 72 (Substitute words in a dictionary)
You probably use special words in your daily messenger use, e.g., LOL, IG, OMG, AFAIK or use emojis for special words, e.g., 😟 for worried.
Write a program that replaces words with their corresponding expansions or emojis, e.g.,
$ echo I read your IG post and I am worried | code-wi/substitute-strings-in-dict.exe
I read your Instagram post and I am 😟
Activity 73 (Is there a bug?)
Analyze the following code snippets. Is there a bug in each code? If yes, where?
#include <stddef.h>
bool is_full;
size_t length;
int main() {
// ...
if (!is_full & length) {
// ...
;
}
}
#include <stddef.h>
#include <stdio.h>
enum { BREAKFAST, LUNCH, DINNER } meal;
int main() {
// ...
switch (meal) {
case BREAKFAST:
puts("Cereals");
puts("Milk");
break;
case LUNCH:
case DINNER:
puts("Vegetables");
puts("Beans");
}
// ...
}
#include <stddef.h>
#include <stdio.h>
#define LINE_SIZE 80
char *line;
int main() {
while (fgets(line, LINE_SIZE, stdout)) {
// ...
;
}
}
puts("yes!" ? a > b : "no!");
#include <stddef.h>
#include <stdio.h>
#include <string.h>
char str[] = "LEVPOS";
int main() {
for (size_t i = 0; i < strlen(str); putc(str[i++], stdout), putc(' ', stdout))
;
}
Activity 74 (Guess the output)
int a = 3, b = 4;
a = b;
b = a;
printf("swapped: %d %d\n", a, b);