mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 00:11:36 +08:00
修正发现的13章以前的一些小问题 (#277)
* Update 07.3.md * Update 07.3.md * Update 07.6.md * fix few problems * Update 10.6 and 10.8 * Update 11.6 and 11.7 * fix some problems before Chap13 * add a dot
This commit is contained in:
@@ -67,7 +67,7 @@ func NewWriter(wr io.Writer) (b *Writer)
|
||||
|
||||
**练习 12.7**:[remove_3till5char.go](exercises/chapter_12/remove_3till5char.go)
|
||||
|
||||
下面的代码有一个输入文件 `goprogram.go`,然后以每一行为单位读取,从读取的当前行中截取第 3 到第 5 的字节写入另一个文件。然而当你运行这个程序,输出的文件却是个空文件。找出程序逻辑中的 bug,修正它并测试。
|
||||
下面的代码有一个输入文件 `goprogram`,然后以每一行为单位读取,从读取的当前行中截取第 3 到第 5 的字节写入另一个文件。然而当你运行这个程序,输出的文件却是个空文件。找出程序逻辑中的 bug,修正它并测试。
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -76,11 +76,12 @@ import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"io"
|
||||
)
|
||||
|
||||
func main() {
|
||||
inputFile, _ := os.Open("goprogram.go")
|
||||
outputFile, _ := os.OpenFile("goprogramT.go", os.O_WRONLY|os.O_CREATE, 0666)
|
||||
inputFile, _ := os.Open("goprogram")
|
||||
outputFile, _ := os.OpenFile("goprogramT", os.O_WRONLY|os.O_CREATE, 0666)
|
||||
defer inputFile.Close()
|
||||
defer outputFile.Close()
|
||||
inputReader := bufio.NewReader(inputFile)
|
||||
@@ -91,7 +92,7 @@ func main() {
|
||||
fmt.Println("EOF")
|
||||
return
|
||||
}
|
||||
outputString := string([]byte(inputString)[2:5]) + "\r\n"
|
||||
outputString := string(inputString[2:5]) + "\r\n"
|
||||
n, err := outputWriter.WriteString(outputString)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
Reference in New Issue
Block a user