Write a c program: ASCII Translator Write a program (asciitrans.c) that gives th
ID: 3672864 • Letter: W
Question
Write a c program:
ASCII Translator Write a program (asciitrans.c) that gives the user the following options: + Enter A to output the ASCII code for a given char + Enter B to output the char corresponding to the given ASCII code If the user enters A, the program should ask to enter one char and outputs the corresponding ASCII code. For example, if the user enters b, the program should output 98. If the user enters B, the program should ask to enter an integer, and output the char with the given ASCII code. For example, if the user enters 98, the program should output b. If the user enters a different option, the program should output an error message that the option is not valid. Modify the program so that it asks the user the following: Do you want to try another conversion (y/n)? If the user types y, the options are displayed again and the program executes the conversion according the option selection. If the user types anything other than y, the program should exit. Compile your program into an executable called asciitrans.
Explanation / Answer
#include <stdio.h>
int main(){
char c;
char option;
printf(" Do you want to continue? {Y|N) ");
scanf("%c", &option);
if (option == 'y' || option == 'Y')
{
printf("Enter a character: ");
scanf("%c",&c); /* Takes a character from user */
printf("ASCII value of %c = %d",c,c);
}else if (option == 'n' || option == 'N')
{
return 0;
}
else
{
printf("Invlid selection.");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.