2012-10-22 4 views
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 

답변

5

당신은 실제로 변수 morse를 인쇄하지 마십시오, 당신은 단지 if -statement의 첫 번째 줄에 할당합니다.

+0

: D는 haha에게 많은 감사를주지 않았다. – RubyNovice

+0

나는 stackoverflow에 새로운 미안하다고 생각한다 : P – RubyNovice

관련 문제