Problem 3: String encoder (40 Points) Write a C program to input a string from t
ID: 3917188 • Letter: P
Question
Problem 3: String encoder (40 Points) Write a C program to input a string from the user and encodes it into a different string of same length according to the following rules. 1. Convert all the lower-case letter in it to the corresponding upper-case letter. 2. Convert all the upper-case letter in it to the corresponding lower-case letter 3. Convert each even digit in it to O' and each odd digit in it to 1 4. Keep any other character unchanged Your program must print the encoded string. You are not allowed to use any string library functions. Name your program file pa3_q3.c HINT: Read about ascii characters and its representations. Read about character arrays. Use scanf) to input the string using a character array of size 30. Example1: Enter the string Ab@#9 8760ZgYRInNc-14Sz Encoded string aB@# 10 1002GyrMn?FF4109 Encoded string h0wDY1 101 @#*IZ>Mf01 01Explanation / Answer
#include <stdio.h>
int main() {
char ch, str[30];
int i = 0;
printf("Enter the string ");
scanf("%s", str);
printf("Encoded string ");
while((ch = str[i++])) {
if(ch >= 'a' && ch <= 'z') {
ch -= 32;
} else if(ch >= 'A' && ch <= 'Z') {
ch += 32;
} else if(ch >= '0' && ch <= '9') {
if((ch - '0') % 2 == 0) {
ch = '0';
} else if((ch - '0') % 2 == 1) {
ch = '1';
}
}
printf("%c", ch);
}
printf(" ");
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.