0

I am using Fortran 90 and I am trying to get the following without new line

do i=1,size
    read*, y(i)
end do

with this, I always get the stdin by using the enter key. Like this Now, I want this without pressing the Enter key, like C++. How can I do it?

Owl0223
  • 1
  • 2
  • Please ask separate questions in separate posts. However, I have no idea what you actually want in your point 1. Point 2 has been asked and answered before, so better not ask it here if you do not want your post to be closed as duplicate. – Vladimir F Героям слава Feb 03 '22 at 17:54
  • I took the liberty to remove your point 2. Please see these duplicates: https://stackoverflow.com/questions/25714322/how-to-write-without-a-newline-in-fortran https://stackoverflow.com/questions/45984672/print-values-without-new-line https://stackoverflow.com/questions/661975/suppressing-line-breaks-in-fortran-95-write-statements And please clarify your main point. – Vladimir F Героям слава Feb 03 '22 at 17:56
  • 1
    Namely, if you do not want to press Enter, how is the program supposed to find out that you finished typing your number? How do you do it in your C++? – Vladimir F Героям слава Feb 03 '22 at 17:59
  • 1
    I think what you want to know is very different from the question you 've asked. Are you asking how to process input from the keyboard immediately, without buffering, without requiring "enter"? C++ can't do that, either. It requires terminal magic that is operating-system specific. Which operating system are you targeting? – Tim Roberts Feb 03 '22 at 18:00
  • @VladimirF You can use space instead of enter key to have seperate inputs in c++ – Owl0223 Feb 03 '22 at 18:12
  • 1
    You can do the same in Fortran. You can use spaces or commas. But you must somehow terminate your input line. In both Fortran and in C++. Perhaps it will be best to show us a C++ example so that we can see what you are actually doing. – Vladimir F Героям слава Feb 03 '22 at 18:21
  • 2
    With `read*, y(i)` you are explicitly asking for each item to be on a new line. Perhaps you are simply after `read*, y(1:size)` (outside the loop) and you can split them over as many lines as you like? It's not clear that's what you mean, so please explain in more detail what you are trying to do. – francescalus Feb 03 '22 at 19:10

0 Answers0