C program – Morse code to text conversion and vice-versa.

by Nideesh C on April 17, 2011 · 0 comments

in C Programming




#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
 
void main()
{
	char str[25],str1[100];
	clrscr();
	fflush(stdin);
	printf("enter the String");
	gets(str);
 
	int j=0;
	for(int i=0;i<=strlen(str);++)
	{
		switch(toupper(str[i]))
		{
		  case 'A':
		  str1[j++]='.';
		  str1[j]='.';
		  break;
 
		  case 'b':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		  break;
 
		  case 'c':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		  break;
 
		  case 'D':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		  break;
 
		  case 'E':
		  str1[j]='.';
		  break;
 
		  case 'F':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		    break;
 
		  case 'G':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		  break;
 
		  case 'H':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		    break;
 
		   case 'I':
		  str1[j++]='.';
		  str1[j]='.';
		    break;
 
		case 'J':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		    break;
 
		case 'K':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		    break;
 
		case 'L':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		  break;
 
		case 'M':
		  str1[j++]='-';
		    str1[j]='-';
		    break;
 
		case 'N':
		  str1[j++]='-';
		  str1[j]='.';
		    break;
 
		case 'O':
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j]='.';
		    break;
 
		case 'P':
		  str1[j++]='.';
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j]='.';
		    break;
 
		case 'Q':
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j++]='.';
		  str1[j]='.';
		    break;
 
		case 'R':
		  str1[j++]='.';
		  str1[j++]='-';
		  str1[j]='.';
		    break;
 
		case 'S':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		    break;
 
		case 'T':
		  str1[j]='-';
		    break;
 
		case 'U':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		    break;
 
		case 'V':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case 'W':
		  str1[j++]='.';
		  str1[j++]='-';
		  str1[j]='-';
		    break;
 
		case 'X':
		  str1[j++]='-';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case 'y':
		  str1[j++]='-';
		  str1[j++]='.';
		  str1[j++]='-';
		  str1[j]='.';
		    break;
 
		case 'Z':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		    break;
 
		case '0':
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j]='-';
		    break;
 
		case '1':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j]='-';
		    break;
 
		case '2':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		    break;
 
		case 'F':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		    break;
 
		case '3':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='-';
		  str1[j]='.';
		    break;
 
		case '4':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '5':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='.';
		    break;
 
		case '6':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '7':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '8':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '9':
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j]='.';
		    break;
 
		case '.':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case ',':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case ':':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '?':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		/* case '\';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break; */
 
		case '-':
		  str1[j++]='-';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case ';':
		  str1[j++]='-';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='-';
		  str1[j]='.';
		    break;
 
		case '(':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case ')':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case ']':
		  str1[j++]='-';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j]='-';
		    break;
 
		case '[':
		  str1[j++]='-';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j]='.';
		    break;
 
		case '}':
		  str1[j++]='-';
		  str1[j++]='.';
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '{':
		  str1[j++]='-';
		  str1[j++]='.';
		  str1[j++]='-';
		  str1[j++]='-';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '"':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '+':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '/':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '%':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '&':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '$':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '*':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '^':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '#':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '@':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='-';
		    break;
 
		case '=':
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j++]='.';
		  str1[j]='';
		    break;
		}
	    j++;
	}
	str1[j-1]='\0';
	puts(str1);
	getch();
 }



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C Program to convert the lower case letters to upper case and vice-versa
  2. C program to read an English sentence and replace lowercase characters by uppercase and vice-versa. Output the given sentence as well as the case converted sentence on two different lines.
  3. Sample – Program to convert temperatures from Celsius to Fahrenheit and vice versa.
  4. C program to accept a figure code and find the ares of different geometrical figures such as circle, square, rectangle etc using switch
  5. C Program to accepts two strings and compare them. Finally it prints whether both are equal, or first string is greater than the second or the first string is less than the second string

Leave a Comment

Previous post:

Next post: