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("%s\n", word);

Assume that this program, when compiled (with clang -o bleep bleep.c) and executed (with ./bleep), is laid out in memory per the below.


Answer the below in bleep.txt.


  1. (4 points.) Not only does this program bleep four-letter words, it also censors puppy and kitten, though not dog or cat, plus quite a few other words. (On much longer inputs, it instead segfaults.) Why does it censor such adorable words?

  2. (2 points.) Propose how to fix the program so that it works as expected.


  1. Which resources, if any, did you find helpful in answering this problem’s questions?

  2. About how long did you spend on this problem’s questions?