Contact Learn C
Copy Program Share Program

Program 208:Generate Morse Code

Program 208:
 
#include<stdio.h>
#include<string.h>
#include<ctype.h>
main()
{
 char *alphamorse[]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
                    "-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-",
     "...-",".--","-..-","-.--","--.."};
 char *nummorse[]={"-----",".----","..---","...--","....-",".....","-....","--...","---..","----."};
 
 int i;
 char str[1000],str1[1000];
 printf("Enter a sentence\n");
 gets(str); 
 i=0;
  while(str[i]!='\0')
  {
 if(str[i]!=' '&&(!isdigit(str[i])))  
 {
     printf("%s ",alphamorse[toupper(str[i])-65]);  
 } 
    if(str[i]==' ')
    {
     printf(" ");
    }
    if(isdigit(str[i])&&str[i]!=' ')
    {
      printf("%s ",nummorse[str[i]-48]);    
    }
    
   i++;
  }
  printf("\n");
 
}
Explanation:

//Coming Soon...

Output:

 

3 comments:

  1. IF I WANTED TO TYPE MORSE CODE AND TRANSLATE IT TO ENGLISH HOW WOULD I DO THIS ?

    ReplyDelete
    Replies
    1. Hi,
      Please check the below url
      http://www.cprograms4future.com/p/decrypt-morse-cipher.html

      Delete
  2. can u send me the explanation of the code

    ReplyDelete

Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide