Print and write in same line

Hey everyone I had a doubt that whether we can able to print the line and take the user input in the same line in the fortran programming is it possible if yes can anyone please help me out in this and give a sample example of it

Your help is much appreciated …

1 Like
write (*, '(a)', advance='no') 'Enter value: '
read (*, *) n
2 Likes

thank you so much this is my initial phase of learning the fortran and this help from you really helped me a lot

by the way can you please explain this this in simple words write (*, ‘(a)’, advance=‘no’)

write is the statement for output, the * selects standard output (terminal/console), '(a)' is the format descriptor for a single string, advance='no' omits the new line at the end of the output.

thank you so much

does advance=no also works with print statement ???

No. Use write(*) instead, which does the same thing.

but it is restricted to only particular bits rights what about if input is dynamic

Sorry, I don’t understand “restricted to only bits rights”. There is really no difference between:

PRINT *, "Hello"
and
WRITE (*,*) "Hello"

They both write to “standard output” and are often considered the same unit number. PRINT is an artifact of the past when there was also a PUNCH statement. It’s just a few characters fewer to write, but omits the I/O control list that lets you do things such as ADVANCE.

let me say you in a code manner

suppose

write (*, ‘(i2, i1)’ ,advance=“no”) n1, n3
consider the above line if the n1 value is 2 digits, n3 value is 1 digit its geting displayed
but where as n1 value if it exceeds the 2 digits like 3 digits its displaying as ***

like how can i achieve it properly

write (*, ‘(i0, 1X, i0)’ ,advance=“no”) n1, n3

1 Like

no its moving the input to the next line

Please show a complete example that demonstrates the problem. What I wrote will not move the cursor to the next line. For example:

D:\Projects>type t.f90
implicit none
integer :: n1, n2, n3
n1 = 23; n3 = 456

write (*, '(i0, 1X, i0, A)' ,advance="no") n1, n3, " Input: "
read (*,*) n2
write (*,*) n2
end

D:\Projects>ifort /nologo t.f90

D:\Projects>t.exe
23 456 Input: 789
         789
2 Likes