Morse code Converter
Morse code is a code where each letter of the English alphabet, each digit and various punctuation characters are represented by a series of dots and dashes.
Write a program that asks the user to enter the string: “Yesterday, I slept most of the night. I saw no stars.” and then calls a function Morse that takes a character array and its size as arguments and converts that string to Morse code, and places the code into another array called morse.
Hint: Place all alphabets in an array named RegularText. Place all Morse codes in an array called MorseCode.
The string is: Use the getline function to input the above string.
The table below shows part of the code.

Character Code Character Code Character Code Character Code
Space space e . l .-.. s …
comma --..-- f ..-. m -- t -
Period .-.-.- g --. n -. u ..-
a .- h …. o --- v …-
b -… i .. p .--. w .--
c -.-. j .--- q --.- x -..-
d -.. k -.- r .-. y -.--

i wrote so far this....

#include<iostream>
#include<cstring>
using namespace std;


void Morse(char[],int);
int main()
{

	
	char string[100];
	cout<<"please enter the line of text to transform it to the morse code.\n";
	cin.getline(string,100,'\n');
	cout<<"\nprinting the array";
	cout<<"\n"<<string<<endl;



	cout<<strlen(string)<<endl;
	
	Morse(string,100);
	
	return 0;
}

void Morse(char s1[],int size)
{	
	char regulartext[50]={' ',',','.','a','b','c','d','e','f','g',
						  'h','i','j','k','l','m','n','o','p','q','r',
						  's','t','u','v','w','x','y'};
	char *morsecode[50]={" ","--..--",".-.-.-",".-","-...","-.-.","-..",".",
						"..-.","--.","....","..",".---","-.-",".-..","--",
						"-.","---",".--.","--.-",".-.","...","-","..-","...-",
						".--","-..-","-.--"};

	for(int i=0;(s1[i])!='\0';i++)
	{
	
		for(int j=0;j<100;j++)
			for(int k=0;k<100;k++)
		{
			if(s1[i]==regulartext[j])
			{
				cout<<regulartext[j]<<endl;
				regulartext[j]=*morsecode[k];
				cout<<morsecode[k];
			}
		}
	}
}
This article has been dead for over six months. Start a new discussion instead.