verifying valid command using char* array

i'm a total beginner playing around, trying to make a Zork-like rpg loosely based on the woodsy area where i live.

here's the function i wrote to check user input against a list of acceptable commands.

1
2
3
4
5
6
7
bool isVALID (char *cmd) {
     int cmdCAT;
     char *dir[]={"go","run","left","right","up","down","north","ne","east","se","south","sw","west","nw","n",
     "e","s","w","kill","fight","hit","cut","the","take","drop","rest","eat","quit",0};
     for (int i=0;dir[i];i++) if (!strcmp(cmd,dir[i])) return false;
     return true;
     }


it iterates through the command list checking each against the user input. i'm trying to use a null value as an exit condition so i can add to the list of commands later as i develop the game. i tried using a null character ("\0") at the end, and empty quotes ("") as well as using nothing at all. the program crashed every time when a nonvalid command was entered. finally got the thing to work using the unquoted zero above. i don't understand why this works. isn't a zero character with no quotes a different data type?
"something" is a pointer to a string that contains the string something. "\0" is a pointer to a string that contains a null character (in fact, two null characters). This pointer itself is not null. To write a null pointer, you have to use 0. A 0 can be converted at compile time to a null pointer of any type.
cool, thanks hamsterman
someone else responded to this question and subsequently deleted their post shortly thereafter for mysterious reasons.

in that post, they linked to a separate thread on this board (recent?) in which different approaches to the problem of my initial question were discussed. anyone else familiar with this thread who could post the link? much apreesh... :)
Sometimes the macro NULL is used to mean a null-pointer (i.e. 0 as a memory address.) NULL is either compiled as or 0l, but I find using NULL helps assert the fact that you want a null-pointer and not the integer .
good to know, thanks.
Topic archived. No new replies allowed.