Programming Example - get_word (with Major Error)

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

char *
get_word(void) {
    int i, c;
    char word[64];
    
    for (i = 0; i < sizeof word - 1; i++) {
        c = getchar();
        if (c == EOF || isspace(c))
            break;
        word[i] = c;
    }
    word[i] = '\0';
    return word; /* ERROR: returning pointer to a local variable */
}

int
main(int argc, char *argv[]) {
    char *s;
    printf("Enter a word: ");
    s = get_word();
    printf("You entered '%s'\n", s);
    return 0;
}

Index