CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2011
    Posts
    2

    Exclamation 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.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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.

  3. #3
    Join Date
    Feb 2011
    Posts
    2

    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' "..

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Morse Code to Text

    Quote Originally Posted by stefanoshea7 View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured