When I type in "exit" the program doesn't seem to terminate from my code below; is there something I am missing or is there better way to terminate the program when the user types "exit"?
In my code you can also see it terminates when an EOF occurs this works properly, it just does not terminate when I type in "exit".
MY CODE:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
int main () {
char input[512];
char * charp;
int len = 0;
printf("> ");
if(fgets(input, 512, stdin) == 0 || input == "exit") { /* reads in input from user no more than 512 chars including null terminator*/
printf("exitting program");
exit(0);
}
printf("You entered: %s", input);
len = strlen(input);
charp = strtok(input, " ' '\t"); /* splits the string on delimiters space '' and tab*/
while (charp != NULL) {
printf("%s\n", charp);
charp = strtok(NULL, " ' '\t");
}
printf("The len of input = %d ", len);
return(0);
}