title: Iterating over a FORTRAN character array
body: <p>Ok, I'm having mucho trouble with the following Fortran 90 code. The program tester should create a character array called input, initialize all the entries to the space character, then get some string from the user and store it in input. The getLength function is supposed to return the last index in the function that isn't a space; so if the user entered the string "Hello, how're you?", then getLength(input) should return 11. It's supposed to work by starting at the end of the given array, and marking where the first non-space character occurs. When I actually try to run it, gfortran says: "Error: Return type mismatch of function getLength at (1) (REAL(4)/INTEGER(4)). What does that mean, what am I doing doing wrong, and how should I fix it? Thanks in advance!</p>
  
  <pre><code>    program tester
      implicit none
      character(len = 1000) :: input
      external getLength
      do i = 1, 1000
          input(i) = " " 
      end do
      read *, input
      print *, getLength(input)
      end program
  
      integer function getLength(array) result (length)
      character(len=1000) :: array
      integer :: lenTemp = 1000
      do while (array(lenTemp:lenTemp) == ' ')
          lenTemp = lenTemp - 1
      end do
      length = lenTemp
      end function
  </code></pre>