How to write in morse code

NetherCraft 0

(1) Morse Code Write a program called morseCode.c that asks the user for an English sentence and then displays the sentence in Morse code. Each letter should be replaced by the code shown on the right (i.e., using dash and dot characters). You will have to convert any lowercase characters to upper case. Also, if any non- alphabetic (and non-space) characters are entered, they are to be represented simply by this string: ?. You must leave a space character between each letter and you should leave 3 spaces between each word Here are a couple of sample runs of the program Enter the sentence to be converted: I LOVE C Here is your sentence in Morse Code: Enter the sentence to be converted: This sentence has 2 #s and 2 symbols Here is your sentence in Morse Code:

Please write in c.

Also Check This  posso intestare un assegno bancario a due persone ???

Answer

Please don’t forget to rate the answer if you are
really satisfied

Before going to the question , Jsut see how to take string input
in C.

1) Using scanf() : It will stop reading as soon it will get
space char. So we can not input string with space using
scanf().

2) gets() : Not reliable can cause buffer overflow.(Never use
this)

3. Using %[^ ]%*c inside scanf() (This is very
useful. Try to remember this) : ^ tells to take
input until newline (or space) doesn’t get encountered. Then, with
this %*c, it reads newline character and here used
* indicates that this newline character is
discarded.

Also Check This  When Watson claimed “Give me a dozen healthy infants?

Now the code is given below with output screenshot..

#include <stdio.h>
# define MAX 1000

void morseEncoder(char * str)
{
for (int i = 0; str[i]; i++)
{
switch (str[i]) {
case ‘A’:
    printf(“.- “);
    break;
case ‘B’:
    printf(“-… “);
case ‘C’:
    printf(“-.-. “);
    break;
case ‘D’:
    printf(“-.. “);
    break;
case ‘E’:
    printf(“. “);
    break;
case ‘F’:
    printf(“..-. “);
    break;
case ‘G’:
    printf(“–. “);
    break;
case ‘H’:
    printf(“…. “);
    break;
case ‘I’:
    printf(“.. “);
    break;
case ‘J’:
    printf(“.— “);
    break;
case ‘K’:
    printf(“-.- “);
    break;
case ‘L’:
    printf(“.-.. “);
    break;
case ‘M’:
    printf(“– “);
    break;
case ‘N’:
    printf(“-. “);
    break;
case ‘O’:
    printf(“— “);
    break;
case ‘P’:
    printf(“.–.”);
    break;
case ‘Q’:
    printf(“–.- “);
    break;
case ‘R’:
    printf(“.-. “);
    break;
case ‘S’:
    printf(“… “);
    break;
case ‘T’:
    printf(“- “);
    break;
case ‘U’:
    printf(“..- “);
    break;
case ‘V’:
    printf(“…- “);
    break;
case ‘W’:
    printf(“.– “);
    break;
case ‘X’:
    printf(“-..-“);
    break;
case ‘Y’:
    printf(“-.– “);
    break;
case ‘Z’:
    printf(“–.. “);
    break;
case ‘
‘:               
//3 space between each word
    printf(”   “);
    break;
default:
    printf(“? “);
}
}
}

Also Check This  Which royals have been subjected to public ridicule?

void to_upper_case(char s[])   // lower case to upper
case converter
{
int c = 0;
while (s[c])
{
if (s[c] >= ‘a’ && s[c] <= ‘z’ && s[c]!=’
‘)
{
s[c] = s[c] – 32;}
c++;
}
}

int main()
{
char str[MAX];

printf(“Enter the sentence to be converted: “);
scanf(“%[^ ]%*c”, str);
to_upper_case(str);    // conert to uppercase before
encoding
morseEncoder(str);
return 0;
}

Computer Science question × + Online C Compiler-online edi × + https://www.onlinegdb.com/online_c_compilert Run Debug Stop H Save Language C 0章 OnlineGDB beta main.c F9 online compiler and debugger for dlc++ code. compile. run. debug. share IDE My Projects Learn Programming Programming Questions We are Hiring Sign Up Login 95 96 void to_upper_case(char s[]) // lower case to upper case converter 97 98 int c =0; 99 while (s[c]) 100 182- 103 s[c] s[c] 32;) 104 c++ 105 166 107 108 int main() 189 110 char str[MAX]; +18.4K 112 printf(Enter the sentence to be converted: n); 113 scan(%(*n]%c, str); 114 to_upper_case(str); I/ conert to uppercase before encoding 115 morseEncoder (str); 116 return ; input ter the sentence to be converted: I love C About FAQ Blog Terms of Use Contact U . GDB Tutorial Credits Program finished with exit code 0 ENTER to exit console https://www.onlinegdb.com/online c_compiler tab-stdin O Type here to search 26-Jan-19



Leave a Reply

Your email address will not be published. Required fields are marked *