File: file_10.f90

package info (click to toggle)
lfortran 0.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 46,332 kB
  • sloc: cpp: 137,068; f90: 51,260; python: 6,444; ansic: 4,277; yacc: 2,285; fortran: 806; sh: 524; makefile: 30; javascript: 15
file content (51 lines) | stat: -rw-r--r-- 1,313 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
program file_10
    implicit none

    character(:), allocatable :: sentence1
    character(:), allocatable :: sentence2
    character(:), allocatable :: sentence3
    character(:), allocatable :: sentence4
    character :: c
    integer :: u = 11, iostat, i

    open(u, file="file_10_data.txt", form="formatted", access="stream", status="old")

    sentence1 = get_prompt(u)
    print *, sentence1
    if (sentence1 /= "hello hi bye.") error stop

    sentence2 = get_prompt(u)
    print *, sentence2
    if (sentence2 /= "1234\nhi hello \n abcd!?") error stop

    sentence3 = get_prompt(u)
    print *, sentence3
    if (sentence3 /= "\n ajdfsalfj;as\n \r jdalfk\14") error stop

    sentence4 = get_prompt(u)
    print *, sentence4
    if (sentence4 /= "dsfjlkf\r\tjkdlfas\n\r\t\n") error stop

    rewind(u)
    do i = 1, 14
        read(u, "(a)", advance="no", iostat=iostat) c
    end do
    print*, iostat
    if (iostat /= -2) error stop

    contains

    function get_prompt(fp) result(input)
        integer, intent(in) :: fp
        character(:), allocatable :: input
        character(1024) :: tmp
        integer ::ios
        read(fp, "(a)", iostat=ios) tmp
        if (ios == 0) then
            input = trim(tmp)
        else
            input = ""
        end if
    end function

end program