title: Go - Scanf and ReadString having conflicts with newline when taking input from redirected .txt file
body: <p>I really want to understand whether there are conflicts regarding Go's ReadString and Scanf functions when reading from a redirected standard input. FYI, developement is done on Ubuntu.</p>
  
  <p>I currently have a recursive function that runs recursively, where in each iteration it asks the user to input the number of integers that will be tested, for then to have a testing session be done within a newly created 'testcase' object. So here's the following code for the function:</p>
  
  <pre><code>func (T *Test) Testing() {
  
  if I == T.N {
      return
  } else {
      //ask for number of integers per testcase
      var input string
      x:=0
  
      _,err = fmt.Scanf("%v\n", &amp;x)
  
  
      //check for correct user input first
      if err != nil {
          fmt.Println("Error: ", err, "LOL")
          ProgramExit()
      }
  
  
      //receive string as input (to accomodate the itegers that are going to be put in a line, with space-seperated integers), terminate at newline
      input,err = in.ReadString('\n')
  
      input = strings.Trim(input, "\n")
  
      //check for correct user input first
      if err != nil {
          fmt.Println("Error: ", err, "Errorororo")
          ProgramExit()
      }
  
      //split any spaces in the input
      input_array := strings.Split(input, " ") 
  
      if l := len(input_array); l!=x {
          fmt.Printf("inconsistent length of input! Inputted number of integers is %v, being ", l)
          fmt.Println(input_array)
          os.Exit(1)
      } 
  
      //make new TestCase object, with its sum and i zeroed first
      T.Tst[I] = &amp;TestCase{x,make([]int,x),0,0} 
  
      //fill TestCase object
      T.Tst[I].Fill(input_array) 
  
      //increase I
      I++ 
  
  //this is where println could be added to check for iterations
  
      //iterate by doing recursion back to method, instead of doing a for loop
      T.Testing() 
  }
  </code></pre>
  
  <p>For clarification, ProgramExit() is just a function to exit the entire program when error occurs. While Fill() is a function to fill up T object using input_array's data.</p>
  
  <p>Now my problem is that when I run the program with the mentioned loop, it can successfully read the inputs that I <strong>manually</strong> typed into the command line below: </p>
  
  <p>(format of input is:</p>
  
  <p>num of testcases</p>
  
  <p>num of integers for testcase 1</p>
  
  <p>num of input integers for testcase 1</p>
  
  <p>num of integers for testcase 2</p>
  
  <p>num of input integers for testcase 2</p>
  
  <p>...</p>
  
  <p>)</p>
  
  <pre><code>2
  4
  3 -1 1 14
  5
  9 6 -53 32 16
  </code></pre>
  
  <p>However when I put the same inputs into a .txt file and redirect that as the input for my program, it gets an EOF error, that seems to happen during the 2nd iteration of the function (i.e. when it tries to read in for 2nd testcase object). Here is the output that I got in the CLI:</p>
  
  <pre><code>$ main &lt; data.txt
  0
  Error:  EOF LOL
  Incorrect input! needs to be an integer input!
  </code></pre>
  
  <p>And this is the output when I put a println function for every successful iteration to print out value of I (I'th iteration)</p>
  
  <pre><code>$ main &lt; data.txt
  1
  0
  Error:  EOF LOL
  Incorrect input! needs to be an integer input!
  </code></pre>
  
  <p>So it does seem that my function is iterating properly however unfortunately after reading the an entire line with ReadString, Scanf would read the next line as a newline (or EOF), instead of reading the next line properly. (Which does not happen when I inputted the integers <strong>manually</strong>). </p>
  
  <p>Could anyone please help point out whether there is a problem with my function that does this, or is there an alternative way to do this properly? (please note that I am developing this for a challenge, and in this challenge, for loop is not allowed lol)</p>
  
  <p>Thanks in advance!   </p>