修正发现的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:
王耀
2016-08-30 02:22:23 +08:00
committed by 无闻
parent a21e30a4a8
commit b0715416ec
7 changed files with 19 additions and 16 deletions

View File

@@ -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)