Question
In the following C program, the main method calls three methods to unlock doors. After unlocking all doors, a write_answer() method will be called. That
In the following C program, the main method calls three methods to unlock doors. After unlocking all doors, a write_answer() method will be called. That is the goal. However, the three unlock door methods are not being called correctly. Edit this program to call the three methods correctly so that write_answer() function can be called.
#include
#include
#include
#include
#include
void write_answer(char* path);
void unlock_second_door(int i);
int var1;
int var2;
int another_var_name = 1;
void an_obscure_name();
void door_3_cb();
int can_unlock_second_door(int i);
int door_alarm_enabled;
void escape_timer() {
if (door_alarm_enabled) {
printf("ESCAPE DOOR DISABLED. SYSTEM CRASH. ");
exit(1);
}
}
void initialize_door_timer() {
if (door_alarm_enabled) {
printf(
"You have %d seconds to disable the alarm. If you fail to do so, the "
"door will lock and you will be trapped ",
30);
signal(SIGALRM, escape_timer);
alarm(30);
}
}
int unlock_first_door(int password) {
var1 = 1;
an_obscure_name();
// algorithm to check password
return password % 4 == 0;
}
void unlock_third_door() {
for (; var2 < 50; var2--) {
var2 *= 2;
}
door_3_cb();
}
int main() {
initialize_door_timer();
int password = 12345;
if (!unlock_first_door(password)) {
printf("You didn't unlock the door! You're dead now ");
exit(1);
}
unlock_second_door(another_var_name);
unlock_third_door();
printf("You escaped! ");
// final desired call
write_answer("desired_output.txt");
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started