Reputation: 43
Converting text from input file to morse code then placing results in an output txt file. File itself is being created but no output is being made.
MAXLINELENGTH = 40
codes = ['.-', '-...', '-.-.', '-..', '.', '..-.',
'--.', '....', '..', '.---', '-.-', '.-..',
'--', '-.', '---', '.--.', '--.-', '.-.',
'...', '-', '..-', '...-', '.--', '-..-',
'-.--', '--..','.----', '..---', '...--',
'....-', '.....', '-....', '--...', '---..',
'----.', '-----']
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
fin = File.open("input.txt", "r")
fout = File.open("output.txt", "w")
line_length = 0
while character = fin.getc
if index = chars.index(character.upcase)
morse = codes[index]
elsif character == " "
fout.print " "
line_length = line_length + 4
end
if line_length >= MAXLINELENGTH
fout.print "\n"
line_length = 0
end
end
fin.close
fout.close
Upvotes: 2
Views: 123
Reputation: 4555
You never actually print the variable morse
, you just assign it on the first line of the if
-statement.
Upvotes: 5