# Unexpected newline / tabbing behaviour in write to string

**URL:** <https://fortran-lang.discourse.group/t/unexpected-newline-tabbing-behaviour-in-write-to-string/10465>\
**Category:** Help\
**Created:** [November 1, 2025, 12:07pm UTC](https://fortran-lang.discourse.group/t/unexpected-newline-tabbing-behaviour-in-write-to-string/10465 "2025-11-01T12:07:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stator](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@Stator](https://fortran-lang.discourse.group/u/Stator)\
**Post date:** [November 1, 2025, 12:07pm UTC](https://fortran-lang.discourse.group/t/unexpected-newline-tabbing-behaviour-in-write-to-string/10465/1 "2025-11-01T12:07:15Z")

</div>

My compiler is GNU Fortran on Windows 10. Details at the bottom.

If I run this:

```fortran
program tab_newline_problem_with_gfortran
  implicit none

  character(len=128) :: str

  write (str,101) ': This is the first line.'//NEW_LINE('A'), &
       ' '// &
       'This is the second line.'
101 format (A,A)

  stop str

end program tab_newline_problem_with_gfortran

```

then I get this:

```auto
STOP : This is the first line.
       This is the second line.

```

which is what I expect.

However, if I remove the leading whitespace string for the second output line and instead insert a T7 tab format specifier like this:

```fortran
program tab_newline_problem_with_gfortran
  implicit none

  character(len=128) :: str

  write (str,101) ': This is the first line.'//NEW_LINE('A'), &
       'This is the second line.'
101 format (A,T7,A)

  stop str

end program tab_newline_problem_with_gfortran

```

then I get this unexpected output:

```auto
STOP : ThisThis is the second line.

```

In addition if, instead of using NEW\_LINE(), I use the “/” newline format specifier, like this:

```fortran
program tab_newline_problem_with_gfortran
  implicit none

  character(len=128) :: str

  write (str,101) ': This is the first line.', &
       'This is the second line.'
101 format (A,/,A)

  stop str

end program tab_newline_problem_with_gfortran

```

then I get this runtime error:

```auto
At line 7 of file tab_newline_problem_with_gfortran.f90
Fortran runtime error: End of file

```

Can someone please explain?

```auto
GNU Fortran (MinGW.org GCC-6.3.0-1) 6.3.0

OS Name: Microsoft Windows 10 Pro Education
OS Version: 10.0.19045 N/A Build 19045
System Model: Latitude 3190
System Type: x64-based PC
Processor(s): 1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 122 Stepping 8 GenuineIntel ~1101 Mhz
BIOS Version: Dell Inc. 1.15.2, 29/07/2021

```

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [November 1, 2025, 12:24pm UTC](https://fortran-lang.discourse.group/t/unexpected-newline-tabbing-behaviour-in-write-to-string/10465/2 "2025-11-01T12:24:47Z")

</div>

Welcome to the forum!

The tab format specifier puts the writing position explicitly to a position relative to the start of the string (line).

The newline specifier introduces a new line, but for an internal write that would be the next element of a string array. It does not mean a new line character. Since your write statement involves a scalar, there is no next element and that gives the run-time error.

---

<div class="post-metadata">

**Author:** ![Stator](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@Stator](https://fortran-lang.discourse.group/u/Stator)\
**Post date:** [November 1, 2025, 1:58pm UTC](https://fortran-lang.discourse.group/t/unexpected-newline-tabbing-behaviour-in-write-to-string/10465/3 "2025-11-01T13:58:07Z")

</div>

@Arjen Thank you. Very clear.
