How to read number of lines present in a text file.
My text file seems to be like:
1
2
3
.
.
.
n
nlines = 0
OPEN (1, file = 'file.txt')
DO
READ (1,*, END=10)
nlines = nlines + 1
END DO
10 CLOSE (1)
print*, nlines
end
P.S. I totally disagree that this question "seems unclear and shows no effort". Man, you just don't know what you're saying. This question is firstly absolutely clear and secondly it does not have to "show any effort" - that's a stupid requirement in this case, because it is a common practice to ask "how to do A in a language B" - with no efforts required.
OR:
nlines = 0
OPEN (1, file = 'file.txt')
DO
READ(1,*,iostat=io)
IF (io/=0) EXIT
nlines = nlines + 1
END DO
CLOSE (1)
print*, nlines