Morse Code

Morse code is a method of transmitting text information as a series of on-off tones, lights, or clicks that can be directly understood by a skilled listener or observer without special equipment. It is named for Samuel F. B. Morse, an inventor of the telegraph.
The algorithm is very simple. Every character in the English language is substituted by a series of ‘dots’ and ‘dashes’ or sometimes just singular ‘dot’ or ‘dash’ and vice versa.
Every text string is converted into the series of dots and dashes. For this every character is converted into its Morse code and appended in encoded message. Here we have copied space as it is. We have considered both numbers and alphabets.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[20],x;
int i;
clrscr();
printf("Enter Input String");
gets(str1);

for(i=0;str1[i]!='\0';i++)
{
x=str1[i];
switch(x)
{
	case 'a':
		printf(".-");
		break;
	case 'b':
		printf("-...");
		break;
	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 '1':
		printf(".----");
		break;
	case '2':
		printf("..---");
		break;
	case '3':
		printf("...--");
		break;
	case '4':
		printf("....-");
		break;
	case '5':
		printf(".....");
		break;
	case '6':
		printf("-....");
		break;
	case '7':
		printf("--...");
		break;
	case '8':
		printf("---..");
		break;
	case '9':
		printf("----.");
		break;
	case '0':
		printf("-----");
		break;
	default:
		printf("Found invalid character: ");
		break;
}
}
getch();
}



No comments:

Post a Comment