-
February 22nd, 2011, 12:32 PM
#1
Morse Code to Text
I've been working on a project to convert user inputted Morse Code to text i.e. convert ".- " to A etc. I'm not sure what is wrong with the program/how to fix it. Here is the code I have so far:
Code:
#include <iostream>
#include <iomanip>
#include <string>
#include <windows.h>
using namespace std;
// Declares a structure of 2 parts - Character and string.
struct Code{
char letter;
string morse;
};
// Array of the structure Code.
Code convert[] ={
{ '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', "-.-- " },{ 'Z', "--.. " },{ '0', "-----" },
{ '1', ".----" },{ '2', "..---" },{ '3', "...--" },
{ '4', "....-" },{ '5', "....." },{ '6', "-...." },
{ '7', "--..." },{ '8', "---.." },{ '9', "----." },
{ '?', "..--.. " },{ '!', "-.-.-- "},{ '$', "...-..- "}
};
void convert_to_morse2(string);
void morse_out(string);
void convert_to_morse(char *);
void morse(char *);
int main ()
{
char str[100];
string text;
cout << "Enter morse code to convert to a string: " ;
getline(cin, text);
convert_to_morse2(text);
system("pause");
// terminate program
return 0;
}
void convert_to_morse2(string s)
{
int i, j;
for ( i = 0; i < s.length(); i++ )
{
for ( j = 0; j < 38; j++ )
{
// Convert characters in s to uppercase before checking for them
if ( toupper(s[i]) == convert[j].letter )
{
letter_out(convert[j].letter);
break;
}
}
}
cout << "\n";
}
void letter_out(string str)
{
int lcv;
char ch;
for (lcv = 0; lcv != str.length(); lcv++) // keep going until the end (0x00) is reached
{
ch = str[lcv];
cout << ch; // Display on screen;
}
}
The error I get is "error C3861: 'letter_out': identifier not found" but I can't see why this is happening. Any help is very much appreciated.
-
February 22nd, 2011, 12:35 PM
#2
Re: Morse Code to Text
You're using letter_out before the compiler has seen it. Either move it before main, or prototype as you have your other functions.
-
February 22nd, 2011, 02:00 PM
#3
Re: Morse Code to Text
Thanks for the advice, I moved it before main but now I get the error " error C2664: 'letter_out' : cannot convert parameter 1 from 'char' to 'std::string' "..
-
February 22nd, 2011, 02:04 PM
#4
Re: Morse Code to Text
Originally Posted by stefanoshea7
Thanks for the advice, I moved it before main but now I get the error " error C2664: 'letter_out' : cannot convert parameter 1 from 'char' to 'std::string' "..
That ought to be pretty self-explanatory. Look at what it's expecting and what you're passing.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|