Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions

Question

4. What sales experience have you had?

Answered: 1 week ago

Question

15-5 How will MIS help my career?

Answered: 1 week ago