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
NEW_LINE(C) returns the new-line character. The argument shall be a scalar or array of the type CHARACTER . Return value: Returns a CHARACTER scalar of length one with the new-line character of the same kind as parameter C .
The 'string' of characters is achieved by including the ('LEN') length specifier to the declaration statement. You should also be aware that when dealing with 'CHARACTER' types the single quote character (')or the double quote character (") can be used as the delimiters for the character type.
Continuation. Any character can be used instead of the plus sign as a continuation character. It is considered good programming style to use either the plus sign, an ampersand, or digits (using 2 for the second line, 3 for the third, and so on).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With