Answer to Question #35038 in C++ for anirudh

Question #35038
Write program to implement a “C1GG filter” in C-language that reads a message entered by the user and translates it into C1GG message: Sample Run: Enter message: Hey dude, C is rilly cool C1GG message: H3Y DUD3, C 15 R1LLY C00L!!!!! The program should convert the message to upper-case letters, substitute digits for certain letters (A->4, B->8, I->1, O->0, S->5), and then append 5 exclamation marks.
Expert's answer
#include <string.h>
#include <stdio.h>
#include <ctype.h>

static char letters[6] = { 'A', 'B', 'E', 'I', 'O', 'S' };
static char digits[6] = { '4', '8', '3', '1', '0', '5' };

int main()
char message[128];
char* index;
char* tmp;
int k;

printf("Enter message: ");

/* Uppercase the string */
for (tmp = message; *tmp; tmp++)
*tmp = toupper(*tmp);

/* Replace the needed letters with digits */
for (tmp = message; *tmp; tmp++)
if (index = strchr(letters, *tmp))
*tmp = digits[index - letters];

/* Append 5 exclamation marks */
for (k = 0; k < 5; k++)
*tmp++ = '!';
tmp = '';

printf("C1GG message: %s
", message);
return 0;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

New on Blog