Question: Need help This code is about to defuse the bomb by entering each password of each stage. I need help on part5 and part6. What

Need help This code is about to defuse the bomb by entering each password of each stage. I need help on part5 and part6. What would be the passward or the output of the methods part5,part6? The code: 

#include

#include

#include

void explode(const int code);

void readInput(char buffer[], const int bufferSize){

int i;

int c;

for(i=0; i<=bufferSize; ++i){

c = getchar();

/* this checks that you are at the end of the line */

/* Windows encodes an end-of-line as two characters: */

/* Linux just uses */

/* This will accept either version */

if(c == ' '){

c = getchar();

}

if(c == ' '){

break;

}

else if(i

buffer[i] = (char)c;

}

}

}

void part5(char buffer[], const int bufferSize){

const char allowed[] = "a3hUD6Cc8bTzv";

int i, j, x;

for(i=0; i

char c;

x = getchar();

if(x == EOF)

explode(10);

else if(x == ' ')

explode(11);

c = (char)x;

for(j=2; j<10; ++j){

if(c == allowed[j]){

buffer[i] = c + 1;

break;

}

}

if(j == 10){

explode(12);

}

}

j = 0;

for(i=1; i

if(buffer[i] != buffer[i-1]){

j = 1;

break;

}

}

if(j == 0)

explode(13);

/* Windows encodes an end-of-line as two characters: */

/* Linux just uses */

/* This will accept either version */

x = getchar();

if(x == ' ')

x = getchar();

if(x != ' ')

explode(14);

}

void part6(const char buf1[], const int bufSize){

char buf2[bufSize];

int i, c;

readInput(buf2, bufSize);

for(i=0; i

if(buf1[i] != buf2[bufSize - 1 - i])

explode(-44);

}

}

void theBomb(){

const int bufSize = 10;

char buffer[bufSize];

int result;

printf("Enter the stage 5 password: ");

part5(buffer, bufSize);

printf("Stage 5 defused. ");

printf("Enter the stage 6 password: ");

part6(buffer, bufSize);

printf("Stage 6 defused. ");

printf("The entire bomb has been defused. ");

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!