2
입력 파일의 텍스트를 모스 코드로 변환 한 다음 결과를 출력 txt 파일에 저장합니다. 파일 자체는 생성 중이지만 출력은 이루어지지 않습니다.파일이 출력되지 않습니다.
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
: D는 haha에게 많은 감사를주지 않았다. – RubyNovice
나는 stackoverflow에 새로운 미안하다고 생각한다 : P – RubyNovice