-
Notifications
You must be signed in to change notification settings - Fork 92
Open
Description
it is not reading the last numbers from the files leading to wrong sum of even and odd numbers due to returned on reaching EOF.
second error: it was reading '\r', so had to trim it too. I did a quick ugly solution:
func source(filename string, out chan int, wg *sync.WaitGroup) {
f, err := os.Open(filename)
if err != nil { panic(err) }
rd := bufio.NewReader(f)
for {
str, err := rd.ReadString('\n')
if err != nil {
if err.Error() == "EOF" {
i, err := strconv.Atoi(str) // ugly code- repetition but the job is done
fmt.Println(i)
if err != nil { panic(err) }
out <- i
f.Close()
wg.Done()
return
} else { panic(err) }
}
str = strings.TrimRight(str, "\r\n")
i, err := strconv.Atoi(str)
fmt.Println(i)
if err != nil { panic(err) }
out <- i
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels