diff --git a/random_challs/valley/source.c b/random_challs/valley/source.c new file mode 100644 index 0000000..e6fa6de --- /dev/null +++ b/random_challs/valley/source.c @@ -0,0 +1,49 @@ +#include +#include +#include + +void print_flag() { + char buf[32]; + FILE *file = fopen("/home/valley/flag.txt", "r"); + + if (file == NULL) { + perror("Failed to open flag file"); + exit(EXIT_FAILURE); + } + + fgets(buf, sizeof(buf), file); + printf("Congrats! Here is your flag: %s", buf); + fclose(file); + exit(EXIT_SUCCESS); +} + +void echo_valley() { + printf("Welcome to the Echo Valley, Try Shouting: \n"); + + char buf[100]; + + while(1) + { + fflush(stdout); + if (fgets(buf, sizeof(buf), stdin) == NULL) { + printf("\nEOF detected. Exiting...\n"); + exit(0); + } + + if (strcmp(buf, "exit\n") == 0) { + printf("The Valley Disappears\n"); + break; + } + + printf("You heard in the distance: "); + printf(buf); + fflush(stdout); + } + fflush(stdout); +} + +int main() +{ + echo_valley(); + return 0; +} \ No newline at end of file