Question
#include #include #include void dot() { printf(.); } void dash() { printf(_); } void spc() { printf( ); } int main() { //declare the necessary
#include
#include
#include
void dot() { printf("."); }
void dash() { printf("_"); }
void spc() { printf(" "); }
int main()
{
//declare the necessary variables
char str[25], str1[100];
// char input;
do
{
//Prompt the user to enter the string
printf(" Enter the String: ");
//Read the string from the user
scanf("%[^ ]", str);
//declare the necessary variables
int j = 0;
int i = 0;
//use for() loop to initialize the loop iterations
for (i = 0; i <= strlen(str); i++)
{
//use switch case to transmit for each
//characters and numbers
switch (toupper(str[i]))
{
//Include the statements for alphabets
case 'A':
dot(); dot();
break;
case 'B':
dot(); dot();
break;
case 'C':
dot(); dot();
break;
case 'D':
dot(); dot();
break;
case 'E':
dot();
break;
case 'F':
dot(); dot();
break;
case 'G':
dot(); dot();
break;
case 'H':
dot(); dot();
break;
case 'I':
dot(); dot();
break;
case 'J':
dot(); dot(); break;
case 'K':
dot(); dot();
break;
case 'L':
dot(); dot();
break;
case 'M':
dot(); dot();
break;
case 'N':
dash(); dot();
break;
case 'O':
dot(); dot();
break;
case 'P':
dot(); dot();
break;
case 'Q':
dot(); dot(); break;
case 'R':
dot(); dot();
break;
case 'S':
dot(); dot(); dot();
break;
case 'T':
dash();
break;
case 'U':
dot(); dot();
break;
case 'V':
dot(); dot(); dot(); dash();
break;
case 'W':
dot(); dot();
break;
case 'X':
dot(); dot();
break;
case 'y':
dot(); dot();
break;
case 'Z':
dot(); dot();
break; case ' ' : spc(); spc(); break;
}//end switch() case
j++;
//end for() loop
str1[j - 1] = '\0';
}}
Can you make this code work? the code job is to take a string from the user and then do something whenever a case is found
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started