Thread: how do I morse code converting program

  1. #16
    Registered User
    Join Date
    Sep 2005
    You're right, it compiled fine, but the output wasn't what I expected, maybe it is my logic that is giving me the problem, do you have any suggestions on how I may approach this problem logically. Any advice that might help point me in the right direction on how to tackle this is greatly appreciated.


  2. #17
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Out of scope
    Create a structure that holds your two variables a character and a string(for morse code)

    Create an array with that structure type the represent each possible character.

    Initialize your alphabet for both plain text and the corresponding morse code.

     // Like this
    characters[15].plainTxt = 'o'
    characters[15].morse = "-.-.-."
    characters[19].plainTxt = 's'
    characters[19].morse = "---"
    Now you got the objects that hold the values of both cases, and it in an easily sortable array. Now go through the string that you read in and (assuming you found the string to be text not morse), have a loop that cycles through the plainTxt values in the array and when it finds a match output the morse value of that array.

    I'm not gonna write this code for you cause I want you to try and grasp the concept I'm telling you.
    Sent from my iPadŽ

  3. #18
    Registered User
    Join Date
    Sep 2005
    Quote Originally Posted by SlyMaelstrom
    sscanf(line, "%[-. \t\n] ", line);
    This doesn't check to see if the input is valid, it checks to see if it's morse code or not. In the case that it isn't morse code then you'll have changed the text that he wants to convert to morse code. In either case, morse code or not, he doesn't want to change what's in the string. That's what I was trying to say.
    But how do you know that just because it isn't morse code it is valid input? If I was writing it I would do two checks - one for morse code and if it fails that, one for valid text. Otherwise who knows what sort of weird characters that you can't convert into morse code could be in there?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. How to make a program that prints it's own source code???
    By chottachatri in forum C++ Programming
    Replies: 38
    Last Post: 03-28-2008, 07:06 PM
  3. large program code ,please help
    By Ash1981 in forum C Programming
    Replies: 14
    Last Post: 01-30-2006, 06:16 AM
  4. Can someone help me understand this example program
    By Guti14 in forum C Programming
    Replies: 6
    Last Post: 09-06-2004, 12:19 PM
  5. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM