6

I want to store newline character in my character buffer variable buff. So far my code goes like this:

       program TYPE_CHECK

c newline storage in buffer 
       character(100), dimension(10)  :: buff
       integer, dimension(10) :: x
       integer :: i

       do i=1,10
       x(i) = i
       enddo

       do j=1,10
       write(buff(j), 1) x(j), x(j)
 1     format(' This is line ', I3, /,
      *       ' This is newline ', I3)
       enddo

       do j=1,10
       write(*, "(A100)") buff(j)
       enddo

       end program TYPE_CHECK

This gives the following error:

At line 13 of file myfoo6.F
Fortran runtime error: End of file

1 Answer 1

10

You can use the NEW_LINE intrinsic function to query the character used to represent newline in formatted stream output. This character typically does what you want when you send it to the console. It is probably easiest to write it out using a separate character data descriptor in your format specification.

Using a slash edit descriptor is actually a request to progress to the next record. For an internal file (writing to a character variable), this is the next array element. In your example code you are passing a scalar as the character variable (so just one record), hence an end of file condition occurs.

Sign up to request clarification or add additional context in comments.

2 Comments

Would you mind adding some sample code to make this a little more obvious?
@JohnE Here is an example taken from link write(*,'(A)') 'This is record 1.'//NEW_LINE('A')//'This is record 2.'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.