Q:

NULL value not being detected

I can't seem to understand what is wrong here, can someone please help me out?
Every time the program runs, it outputs all the words of the sentence. It then tries to copy a 11th word (there is only 10), which it shouldn't since it should be detecting the NULL. My TA couldn't figure out what was wrong, so either he didn't try very hard or it's more complicated than i previously thought.
#include <stdio.h>
#include <string.h>

struct myWord{
    char Word[21];
    int Length;
};

int main(){
    struct myWord WordList[21];
    char myString[] = "the cat in the hat jumped over the lazy fox";
    char* temp;
    int n = 0, i;

    temp = strtok(myString, " ");
    while (WordList[n].Word != NULL){
        printf("%s\n", temp);
        strcpy(WordList[n].Word, temp);
        temp = strtok(NULL, " ");
        WordList[n].Length = strlen(temp);
        n++;
    }
    printf("works!\n");
    return 0;
}

A:

You should in fact, test if temp != NULL in your while loop. Plus, you should swap
    temp = strtok(NULL, " ");
    WordList[n].Length = strlen(temp);

with
    WordList[n].Length = strlen(temp);
    temp = strtok(NULL, " ");

if you want the correct length of the word
temp = strtok(myString, " ");
while (temp != NULL)
{
    printf("%s\n", temp);
    strcpy(WordList[n].Word, temp);
    WordList[n].Length = strlen(temp);
    temp = strtok(NULL, " ");
    n++;
}

