50 lines
955 B
C
50 lines
955 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
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;
|
|
}
|