✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
The following piece of code encrypts the line of text taken as input by shifting each character of the line by a key value. It uses the index notation. (Assume MAX is a #define constant.)
char line[MAX]; int i = 0, key = 4; printf("Enter a line of text:"); scanf("%[^\n]", line); while (line[i]) { putchar(line[i]+key); i++; }
In an attempt to rewrite the entire code using pointer notation, a beginner program made the following attempt:
char line[MAX]; int key = 4; printf("Enter a line of text: "); scanf("%[^\n]", line); while (*line) { putchar(*line + key); line++; }
Unfortunately, the code would not compile. Can you find the mistake and fix it? You do not have to rewrite the entire code segment, but only the parts you are modifying.
Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!