Question: The following code decodes a secret message and prints out the decoded message as: c rocks! Unfortunately, some bugs have crept into the code and
The following code decodes a secret message and prints out the decoded message as:
c rocks!
Unfortunately, some bugs have crept into the code and need to be found and corrected. You should take the version of the code you have been given and use your debugging skills (on a compiler) to find the three (3) bugs in the code and fix them. For each bug you find and correct you should:
a) Write the original line number on which you found the bug, b) Explain what was wrong with this line c) Explain what you did to fix the bug d) Show the original line(s) of code with the bug in it e) Show your fixed line(s) of code that corrects the bug
Code:
#include
int main(void) { char alpha[] = { "abcdefghijklmnopqrstuvwxyz !-." }; int secret[] = { 92, 90, 77, 78, 92, 74, 76, 91 }; int i, alen = 0; int offset = 0; int messageLen = 8; for (alen = 0; alpha[alen] != '\0'; alen++) { alen = 1; } offset = alen / 7; for (i = 1; i < messageLen; i++) { int off = (secret[i] - offset + 1) % alen; int idx = (i % 2) ? off : (alen - off); printf("%c%s", alpha[idx], (i == 5) ? "\0" : ""); } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
