You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
}
}
The text was updated successfully, but these errors were encountered:
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) }
}
The text was updated successfully, but these errors were encountered: