Possible Duplicate:
How do I properly compare strings in C?
I started C programming yesterday so I'm very new to this language. I'm using fget() to receive user input and then using strtok() to tokenize the input. I'm trying to see if the first word of the input is equal to "exit", at which point the program will exit. For some reason it's not working. Here is my code.
#include <stdio.h>
#include <string.h>
#define MAX_LINE 1024
#define MAX_TOKEN 64
#define SEPARATORS " \t\n"
main(){
char line[MAX_LINE];
char *token[MAX_TOKEN];
int loop = 1;
int i;
while (loop != 0){
fgets(line, sizeof(line), stdin);
token[0] = strtok(line, SEPARATORS);
printf("token[0] = %s\n", token[0]);
if (token[0] == "exit"){
printf("%s", "Beep Boop Boop Boop");
loop = 0;
}
for (i = 0; token[i] = strtok(NULL, SEPARATORS); i++){
printf("token[%d] = %s\n", i, token[i]);
}
}
}
The following code is what is not working correctly.
if (token[0] == "exit"){
printf("%s", "Beep Boop Boop Boop");
loop = 0;
}