concierge/challenge/challenge.c
anthraxx 4a28a8debd some manual (unnecessery) free for good manner
its not needed because OS is responsible to cleanup
mem allocated by terminating process, but its still
a good manner to explicitly free everything that gets
allocated...
yes this is "noise" if it terminates but neither does
harm to feel being responsible to clean up everything
ourselves. :)

at least valgrind is silently happy :P :D
2014-06-10 23:14:29 +02:00

32 lines
729 B
C

#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: ");
/* 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);
}
/* 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);
}
}