char buf[BUF_SIZE + 1];
printf("[Enter Command]: \n");
num_read = read(STDIN_FILENO, buf, BUF_SIZE);
if (num_read == 5) {
exit(0);
}
I want to check if the user input is the string "exit"
and exit the program if it is. The snippet above works but it will exit on all 4 letter strings. I only want it to exit on the string "exit"
.
I don't understand why the code below doesn't work:
if (strcmp("exit", buf) == 0) {
exit(0);
}