0

It's a very simple task, but there are two problems with my current implementation.

  1. I want it to read a whole line. It currently only reads the first few characters if they are separated by space. I think this can be fixed with a custom format, but I don't know what to use.
  2. Fortran needs to know how much to allocate and with my current implementation it can only read 10 characters. I want it to read without a limit. The only way that I know that can fix this right now is asking the user, how many characters they want to be read, but other programming languages can do this without it and I don't want to ask the user for additional things.
program main
    implicit none
    character(:), allocatable :: name

    allocate(character(10) :: name)

    read *, name
    print *, name

    deallocate(name)
end program main
  • https://stackoverflow.com/questions/34746461/how-to-read-text-files-with-possibly-very-long-lines-in-fortran might be of use – Ian Bush Jan 18 '23 at 19:21
  • You can read a 100 long character or 256 long character if you want. Surely this number of digits is sufficient in this case, your computer does not have that much memory. There are deferred length strings but you cannot read to an unallocated one anyway. The solution linked by Ian should work but for this case is really overkill. – Vladimir F Героям слава Jan 18 '23 at 19:23

0 Answers0