Contact Learn C
Copy

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:

 

4 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
  3. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. شروحات الألعاب

    ReplyDelete

Donate

Download App and Learn when ever you want

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