![]() |
|
#1
|
|||
|
|||
english to morse revisitedI recently had a post about this and am sort of revisting my problem in more detail now. i am trying to write a program that will convert English to morsecode. i am trying to make it where there will be a space between each morse equivalent, and will print to a new line when the output gets to the
80th column, but not starting a new line in the middle of the morse equivalent. for a simple test i use the string me[] = "greg". i expect the results to be... --. .-. . --. i am not getting this result.. i would apprectiate it if some one can lend me a helping hand and tell me why its not giving me the output i expect. my code is below. CPP / C++ / C Code:
|
|
#2
|
||||
|
||||
Re: english to morse revisitedQuote:
Your code does the work. Simply remove the CPP / C++ / C Code:
What you actually did is wait for your to enter a character for the program to print each morse character after the first one. Why not write a function that returns the morse code matching the character you passed it ? CPP / C++ / C Code:
You are comparing an integer with void * (as the warning tells ... ) Kobi. __________________
It's actually a one time thing (it just happens alot). |
|
#3
|
||||
|
||||
Re: english to morse revisitedQuote:
CPP / C++ / C Code:
This way, any character in your buffer an be displayed/returned by CPP / C++ / C Code:
CPP / C++ / C Code:
Get a list of the ASCII characters in order and simply put the Morse Code string in the same position. For example SPACE (32) 1st " " Double Quote (34) 3rd, ".-..-. " 1 (49) 18th ".---- " A (65) 34th ".- " a (97) 66th ".- " Something like that. I may not have the numbers exact (from memory) but this would give you the idea. This will give you a list of all the ASCII characters in order: CPP / C++ / C Code:
__________________
Age is unimportant -- except in cheese |
|
#4
|
|||
|
|||
Re: english to morse revisitedok i am coming close. i didnt exactly do what you said to do. i kinda did it a different way. ive got it working correctly EXCEPT for the fact that i need 3 spaces between each work in the morse code transformation. for example, if i am trying to convert "greg glisch" to morse code i expect to get
--. .-. . --. {3 spaces here} --. .-.. .. ... -.-. .... i am not getting this. i am getting --. .-. . --. {1 space here } --. .-.. .. ... -.-. .... can someone tell me why its not printing the 3 spaces between the 2 words? my code is as follows... CPP / C++ / C Code:
some one please help me...i am at the end of the rope here. thank you in advance. |
|
#5
|
||||
|
||||
Re: english to morse revisitedQuote:
You need to check for space and insert three spaces to the output where encountered ... Where are you checking for space ? Kobi. P.S You are using an escape sequence that doesn't exist . Look at the warnings from the compiler. __________________
It's actually a one time thing (it just happens alot). |
|
#6
|
|||
|
|||
Re: english to morse revisitedi am checking for space here...
CPP / C++ / C Code:
now, when looking at this i did see that i was checking for NULL instead of ' '. but i went back and changed it to test for space and it still doesnt work correctly. |
|
#7
|
||||
|
||||
Re: english to morse revisitedThis is how I would approach this problem :
CPP / C++ / C Code:
Does this approach seem simpler ? to me it does. Functions are very convenient to use if you define them correctly. Note that I didn't do much work after defining the conversion functions... Try to use the conversion from morse to english on your own ... Best regards, Kobi. __________________
It's actually a one time thing (it just happens alot). |
|
#8
|
|||
|
|||
Re: english to morse revisitedok...
this "program' that i am writing is eventually going to be converted into a function. i am just running it as a program at the moment so i can see my results. the code below is going to become a function called engltomorse() when i get it working correctly. all i need for this to happen is to have the printing start printing to a new line when the output of the morse line becomes greater than 80. BUT, it must not start the new line in the middle of the morsecoded word. so somehow i need to check to see that the position of the printer plus the length of the next "morse word is < 80. if it is i may print it on the same line, if not i must start a new line in the very first column. my code is below. suggetstions are greatly appreciated. CPP / C++ / C Code:
thank you in advance. |
|
#9
|
||||
|
||||
Re: english to morse revisitedHey Greg.
You are very stubborn. I like that. What you need to do is count the number of characters you print. Do so by declaring a counter, and each time you print something, add it's length to the counter. Now - Before you actually print anything, check the counter. If it's length is 80 or more, set it back to 0 and start a new line. 1. I intentionally didn't write code. You seem to know how to use counters and strlen. 2. Try to get rid of the compiler warnings, you will find that they are very logical ... (Ask me how, if you try and fail). Best regards, Kobi. __________________
It's actually a one time thing (it just happens alot). |
|
#10
|
|||
|
|||
Re: english to morse revisitedkobi... or anyone...
i have just finished "debugging" my code when you replied. now..i know my problem is that i am printing the characters to the screen while i am testing them. but, i am completly stumped as of how to keep my code " the same" and test the future length of the words without printing. all i can think of is some type of loop somewhere. here are the existing code below. CPP / C++ / C Code:
I GREATLY appreciate your help. please reply soon. time is starting to become crucial. |
Recent GIDBlog
Toyota - 2008 August Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| need help converting between morse and english | fadedg2 | C Programming Language | 2 | 29-Oct-2005 10:02 |
| Dynamic memory allocation - Dangling pointers revisited | karthikeyansen | C++ Forum | 13 | 27-Jul-2005 15:30 |
| D3D error when running fullscreen games/programs - help?! | daa709 | Computer Hardware Forum | 4 | 01-Jul-2005 08:03 |
| Morse Code for C | sibyl03 | C Programming Language | 1 | 13-Oct-2004 00:00 |
| For the 'Johny English' in you | JdS | Open Discussion Forum | 3 | 09-May-2003 04:49 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The