Spy investigating company is working on some highly confidential material and wi
ID: 3533585 • Letter: S
Question
Spy investigating company is working on some highly confidential material and will be sending their messages in messages in secret code.
All vowels (A,I,E,O,U) will be replaces by the next lowercase character in the alphabet. (example, 'A' will be changed to 'b')
All spaces will be replaced by two lowercase z's.
All periods will be replaced by an uppercase Z.
All consonants will be replaced by the previous uppercase character. (example, 'B' will be changed to 'A')
Note:
1.The message must end with CTRL Z.
2.Must use getchar for input and a switch statment for manipulatio nof the characters.
3.All messages will consists of uppercase letters of the alphabet, spaces, or periods.
4.The input should be no longer than 60 characters. If it is print out an error message and stop processing.
5.To change the case of a character use the tolower and toupper functions. Remember, in order to use these functions, include
#include<ctype.h>
the input:
CAN YOU DECODE THIS MESSAGE.
The original line is:
CAN YOU DECODE THIS MESSAGE.
The modified line is :
ZfFbRRfLzzRjGSzzfCpBfCzzvpXzzMbB
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
char temp;
char input[60];
char output[120]; //double original size even if
int counter = 0, outCounter = 0;
printf("Message must be contain uppercase letters, spaces, and periods. ");
printf("End message with Ctrl Z. ");
printf("Input message to decode: ");
while((temp = getchar()) != 26){
if(counter > 59){
printf(" The input was longer than 60 characters. Stopping encoding process... ");
return 0;
}
input[counter] = temp;
switch(input[counter]){
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
output[outCounter] = tolower(input[counter]+1);
break;
case ' ':
output[outCounter] = 'z';
outCounter++;
output[outCounter] = 'z';
break;
case '.':
output[outCounter] = 'Z';
break;
default:
output[outCounter] = input[counter] - 1;
break;
}
counter++;
outCounter++;
}
//set null terminates
output[outCounter] = '';
input[counter] = '';
printf("The original line is: %s ", input);
printf("The modified line is: %s ", output);
printf("The modified line reversed is: ");
int i;
for(i = outCounter-1; i >= 0; i--){
printf("%c", output[i]);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.