を書きます。 マトリックスは、その中に文字列を含むリストです。 私が書いているとき、私は初めからデータを上書きする必要があります。基本的には毎回ファイルを削除します。私はこれのためにベターの解決策が必要です。 主な問題は、カップルの読み取りとファイルのwrithingsが壊れた後です。読書やScheme
システムエラー:アクセスが拒否されました;エラー番号= 5
マイコード:
;reading file returning matix of strings
(define (file-reader file-name)
(define pointer (open-input-file file-name))
(define (helper line)
(cond
((equal? line eof) '())
((cons (list line) (helper (read-line pointer))))))
(list-matr (helper (read-line pointer)))
)
;converting matrix of string to matrix of lists with strings inside
(define (list-matr str-matr)
(define (helper str-matr line-num)
(cond
((null? str-matr) '())
((= line-num 1) (cons (map (lambda (x) (string-append x "?")) (string-split (caar str-matr) "? ")) (helper (cdr str-matr) (+ line-num 1))))
((cons (string-split (caar str-matr) " ") (helper (cdr str-matr) (+ line-num 1))))))
(helper str-matr 1))
;saving in file
(define (writer file-name questions answers)
(cond
((file-exists? file-name) (delete-file file-name)))
(write-to-file file-name (string-append (string-join questions) "\n"))
(define (helper cur-l ans)
(cond
((null? ans))
((helper (write-to-file file-name (string-append (string-join (car ans)) "\n")) (cdr ans)))))
(helper '() answers)
)
(define (write-to-file path string)
(call-with-output-file path #:exists 'append
(lambda (newline)
(display string newline))))
コマンドの機能を呼び出すため。
(ファイル・リーダー「data.txtを」)
(ライター「data.txtを」質問の答え)
私はファイルを閉じないという問題がから来たと思うが、私ができますその命令をどこに置くべきかを把握していない。
私のコードは、あなたが私のファイルから行列を読み書きのための他の例を与えることができる非常に悪い場合。
ありがとうございます。