user2884862
user2884862

Reputation: 11

Reading lines from a data file

Problem: Reading data file with multiple entries on a single line

~~~~~~~~~~~~

Problems with that solution:

~~~~~~~~~~~~

Is there any other way of doing this?

Upvotes: 1

Views: 119

Answers (2)

IanH
IanH

Reputation: 21441

Using deferred length character and non-advancing reads avoids the problems you mention in your question.

Continuing to parse of the resulting line using internal IO with explicit formats then avoids the potential for user "surprise" associated with the more obscure features of list directed formatting and allows far more scope and control over input error detection and reporting.

Upvotes: 2

M. S. B.
M. S. B.

Reputation: 29401

You can directly read multiple items from a one or multiple lines. For example:

read (5, *) a, b, c, d

will read four values from one to many lines.

Upvotes: 2

Related Questions