diff --git a/challenge/challenge.c b/challenge/challenge.c index a674424..604f1a5 100644 --- a/challenge/challenge.c +++ b/challenge/challenge.c @@ -3,30 +3,24 @@ #include int main() { - int bytes_read; + int ret; size_t nbytes = 0; char *my_string = NULL; char *password = "23door42\n"; puts("Please enter Password: "); + ret = getline(&my_string, &nbytes, stdin); - bytes_read = getline(&my_string, &nbytes, stdin); - - if(bytes_read == -1) { + if (ret == -1) { puts("Error"); - free(my_string); - return -1; + } else if (strcmp(my_string, password) == 0) { + puts("Success"); + ret = 0; } else { - if (strcmp(my_string, password) == 0) { - puts("Success"); - free(my_string); - return 0; - } else { - puts("How about no?!"); - free(my_string); - return -1; - } + puts("How about no?!"); + ret = -1; } - return 0; + free(my_string); + return ret; }