Question: #include #include int main(){ char filename [30]; FILE * ifp = NULL; int keys[7], i=0, num, input[7], hasht[101] = {0}, flag = 0; int count

#include #include

int main(){ char filename [30]; FILE * ifp = NULL; int keys[7], i=0, num, input[7], hasht[101] = {0}, flag = 0; int count = 0;

while(ifp == NULL){ printf("What is the name of the file? "); scanf("%s", filename); ifp = fopen(filename, "r"); }

// fclose(file);

printf("To get to me treasure you'll have to figure out which of me 100 keys are used in the 7 locks of me treasure chest. ");

while(1){ printf("Which keys will ye use? "); for(i = 0; i < 7; i++) scanf("%d", &input[i]);

for(i = 0; i < 7; i++){ if(hasht[(input[i] - 1)] == 0) hasht[(input[i] - 1)] = 1;

else{ printf("You can only use each key once, matey! "); flag = 1; } } if(flag != 1){ for(i = 0; i < 7; i++){ if(hasht[(keys[i] - 1)] != 1) break; else count++; } if(count != 7) printf("%d of those keys are correct, matey! But are they in the right order? ", count); else{

for(i = 0; i < 7; i++){ if(input[i] != keys[i]) break; }

if(i == 7){ printf("Arr! You've opened me treasure chest and found... "); printf("A map! To the rest of me treasure on Treasure Island. "); printf("Hahaha! "); break;

}else{ printf("7 of those keys are correct, matey! But are they in the right order? "); } } } } return 0; }

I have this code im prompting the use to input a .txt file

'input.txt'

(which has the information below on it)

2 14 74 8 36 4 11

however after testing the code I get a program crash.

The first WHILE loop seems to be causing the issue but im not to sure how to fix it

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!