文件统计在计划中

编程入门 行业动态 更新时间:2024-10-28 00:28:10
本文介绍了文件统计在计划中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我会先走,这是家庭作业。下面的代码定义了一个函数 countup ,称为:

file1)

看起来循环无限期运行。为什么,我该如何解决这个问题?

(define stats (lambda(srcf)开始(定义在(open-input-file srcf))(let loop((l 0)(w 0)(c 0)((#())(char(read-char in)))(case char ((#\ newline)(loop(+ l 1)w(+ c 1) -char in)))((#\space#\tab)(loop l(+ w 1)(+ c 1)(read-char in))) (else)(loop lw(+ c 1)(read-char in)))))(close-input-port in) (display l) $($$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b) ;; srcf =源文本文件(define countup (lambda(srcf lstf)(stats srcf)))

$ b $从文件中读取字符的程序必须有这个条件: b

(cond((eof-object?the-char)'finished) ...)

看看这个回答看到一个类似于你正在编写的程序,这可能是有帮助的。

I'll be upfront: this is Homework. The following code defines a function countup, called as:

(countup "file1")

It appears that the loop is running indefinitely. Why, and how can I fix this?

(define stats (lambda (srcf) (begin (define in (open-input-file srcf)) (let loop ( (l 0) (w 0) (c 0) (char (read-char in))) (case char ((#\newline) (loop (+ l 1) w(+ c 1) (read-char in))) ((#\space #\tab) (loop l (+ w 1) (+ c 1) (read-char in))) (else (loop l w (+ c 1) (read-char in)))) ) (close-input-port in) (display l) (display " ") (display w) (display " ") (display c) (newline) '())) ) ;; srcf = source text file (define countup (lambda (srcf lstf) (stats srcf) ) )

解决方案

A program that reads characters from a file must have this condition somewhere:

(cond ((eof-object? the-char) 'finished) ...)

Take a look at this answer to see a procedure similiar to the one you're writing, it might be helpful.

更多推荐

文件统计在计划中

本文发布于:2023-06-04 21:18:50,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   计划

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!