concierge/challenge/challenge.c

32 lines
729 B
C
Raw Normal View History

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
const char *password = "23door42\n";
int main(void) {
size_t input_size = 0;
char *input_line = NULL;
printf("Please enter Password: ");
2014-06-10 22:56:01 +02:00
/* read in password from standard input, exit on error. */
if (getline(&input_line, &input_size, stdin) == -1) {
perror("Error");
free(input_line);
exit(EXIT_FAILURE);
}
2014-06-10 22:56:01 +02:00
/* compare password, print info, exit appropriately */
if (strcmp(input_line, password) == 0) {
puts("Success!");
free(input_line);
exit(EXIT_SUCCESS);
} else {
puts("How about no?!");
free(input_line);
exit(EXIT_FAILURE);
}
}