Bleep
Consider the program below, which is intended to bleep (i.e., censor) four-letter words.
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
bool bleep = false;
char word[4];
scanf("%s", word);
if (strlen(word) == 4)
{
bleep = true;
}
if (bleep)
{
printf("$#@!\n");
}
else
{
printf("%s\n", word);
}
}
Assume that this program, when compiled and executed, is laid out in memory per the below.
Answer the below in bleep.txt
.
Questions
-
(4 points.) Not only does this program bleep four-letter words, it also censors
puppy
andkitten
, though notdog
orcat
, plus quite a few other words. (On much longer inputs, it instead segfaults.) Why does it censor such adorable words? -
(2 points.) Propose how to fix the program so that it works as expected.
Debrief
-
Which resources, if any, did you find helpful in answering this problem’s questions?
-
About how long did you spend on this problem’s questions?