title: Go channels and I/O
body: <p>First function </p>
  
  <blockquote>
    <p>ReadF2C</p>
  </blockquote>
  
  <p>takes a filename and channel, reads from file and inputs in channel.
  Second function </p>
  
  <blockquote>
    <p>WriteC2F </p>
  </blockquote>
  
  <p>takes 2 channels and filename, takes value of each channel and saves the lower value in the output file. I'm sure there is a few syntax errors but i'm new to GO</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "bufio"
      "os"
      "strconv"
  )
  
  func main() {
      fmt.Println("Hello World!\n\n")
      cs1 := make (chan int)
      var nameinput string = "input.txt"
      readF2C(nameinput,cs1)
      cs2 := make (chan int)
      cs3 := make (chan int)
      cs2 &lt;- 10
      cs2 &lt;- 16
      cs2 &lt;- 7
      cs2 &lt;- 2
      cs2 &lt;- 5
      cs3 &lt;- 8
      cs3 &lt;- 15
      cs3 &lt;- 14
      cs3 &lt;- 1
      cs3 &lt;- 6
      var nameoutput string = "output.txt"
      writeC2F (nameoutput,cs2,cs3)
  }
  
  func readF2C (fn string, ch chan int){
      f,err := os.Open(fn)
      r := bufio.NewReader(f)
      for err != nil { // not end of file 
  
      fmt.Println(r.ReadString('\n'))
      ch &lt;- r.ReadString('\n')
      }
  
      if err != nil {
          fmt.Println(r.ReadString('\n'))
              ch &lt;- -1
      }
  
  }
  func writeC2F(fn string, // output text file
  ch1 chan int, // first input channel
  ch2 chan int){
      var j int = 0
      var channel1temp int
      var channel2temp int
          f,_ := os.Create(fn)
          w := bufio.NewWriter(f)
      channel1temp = &lt;-ch1
      channel2temp = &lt;-ch2
      for j := 1; j &lt;= 5; j++ {
       if (channel2temp &lt; channel1temp){
  
          n4, err := w.WriteString(strconv.Itoa(channel1temp))
          } else{
  
          n4, err := w.WriteString(strconv.Itoa(channel2temp))
          }
      w.flush()
      }
  }
  </code></pre>
  
  <p>This is the error messages I get: </p>
  
  <pre><code>prog.go:38: multiple-value r.ReadString() in single-value context
  prog.go:65: w.flush undefined (cannot refer to unexported field or method bufio.(*Writer)."".flush)
  </code></pre>