Computer Science Canada

Reading spaces in Turing

Author:  Luganchan [ Thu Nov 28, 2013 1:11 pm ]
Post subject:  Reading spaces in Turing

What is it you are trying to achieve?
I am trying to make an english to morse decoder/encoder in Turing.


What is the problem you are having?
In morse, letters are separated by a space, while words are separated by three spaces. The problem is that Turing does not read the spaces in between the words within a string.When we input "Magic The Gathering", we get the morse output for MagicTheGathering, turing won't read the spaces.




Please specify what version of Turing you are using
Turing 4.1

Author:  DemonWasp [ Thu Nov 28, 2013 1:35 pm ]
Post subject:  RE:Reading spaces in Turing

Without seeing your code it's hard to be sure exactly what's wrong, but I assume that you're not using 'get' correctly.

Look at http://compsci.ca/holtsoft/doc/get.html , specifically part (c), and the bit about "Line-oriented input".

Author:  Raknarg [ Thu Nov 28, 2013 3:12 pm ]
Post subject:  RE:Reading spaces in Turing

Are you using get statements? Try this:

get input :*

The ":*" after it tells Turing to obtain the entire line you type. If you don't include it, it will only take the first word you input. Is this your problem?

Author:  Luganchan [ Thu Nov 28, 2013 5:55 pm ]
Post subject:  RE:Reading spaces in Turing

I use the get input :*
but it does not register spaces as part of the string

Author:  Raknarg [ Thu Nov 28, 2013 6:06 pm ]
Post subject:  Re: Reading spaces in Turing

Are you certain you did it correctly?

Author:  Luganchan [ Thu Nov 28, 2013 6:58 pm ]
Post subject:  Re: Reading spaces in Turing

this is the part of my code that is in question, i got it to work, but the spaces it outputs in morse take up multiple line upon output.
Turing:


var letter : array 1 .. 53 of string :=init("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",".",",","?","'","!","/","(",")","&",":",";","=","+","-","_",'"',"$")
var morse : array 1 .. 53  of string :=init (".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..","-----",".----","..---","...--","....-",".....","-....","--...","---..","----.",".-.-.-","--..--","..--..",".----.","-.-.--","-..-.","-.--.","-.--.-",".-...","---...","-.-.-.","-...-",".-.-.","-....-","..--.-",".-..-.","...-..-")
var num :array 1..53 of int
var x :int
var word,character:string
var final :string := ""
procedure engmorse
    loop
        get word : * %asks the user for a word
        for j : 1 .. length (word) %runs a check to output the needed number of morse letters
            for i : 1 .. 53%checks all the synced letter for the correct one
                if word (j) = letter (i)
                        then
                    put morse (i), " " .. %outputs the corresponding morse letter
%**********************************************************%
%                                       problematic code                                      %
%**********************************************************%
                    elsif word (j) = " "
                            then
                        put "    " ..
%**********************************************************%
%                                 end problematic code                                      %
%**********************************************************%
                   
                else
                end if
            end for

        end for
    end loop
end engmorse
engmorse

Author:  Raknarg [ Thu Nov 28, 2013 7:42 pm ]
Post subject:  RE:Reading spaces in Turing

it took me some time, but I figured it out.

Go over your code when the letter is a space. It goes over that code 53 times. Think about it.

Author:  DemonWasp [ Thu Nov 28, 2013 7:59 pm ]
Post subject:  RE:Reading spaces in Turing

Seems to be working fine for me, except that you're printing those four spaces 53 times for every space that occurs in 'word'.

Author:  Luganchan [ Thu Nov 28, 2013 8:01 pm ]
Post subject:  Re: Reading spaces in Turing

wow, can't beleive i didn't notice that, thank everyone


: