Try:
#define BUFF_LEN 256 char input[BUFF_LEN]; fgets(input, BUFF_LEN, stdin);
What you have *input is a pointer to a memory address that has not been allocated, so it cannot be used by your program. The result of using it, like you, is undefined, but usually leads to a segmentation fault . If you want to access it as a pointer, you first need to select it:
char *input = malloc(BUFF_LEN);
... of course, check that for failure (NULL), then free () is after you finish using it.
Edit:
At least according to a single UNIX specification , fgets () is guaranteed to terminate the zero buffer. It does not need to initialize input [].
As others have said, there is no need to include null / newlines when using strcmp ().
I also highly recommend that you get used to using strncmp() now, while starting to avoid many problems in the future.
source share