Here is my code:
printf("Please input a command\n");
char *input;
input = malloc(sizeof(char) * 50);
if(fgets(input, 50, stdin) != NULL) {
if(strcmp(input, "end\0") == 0) {
printf("END");
}
}
For some reason when I input 'end', it doesn't print "END". What is the problem here that is causing the loop condition to fail? strcmp(input, "end\0") == 0
Should return 0 when the input pointer is equal to "end\0"
? I've also tried strcmp(input, "end") == 0
and this doesn't work either. How can I fix this?