Skip to content

How to detect EOF? #43

@XiaoPanPanKevinPan

Description

@XiaoPanPanKevinPan

I'm a newbie, so if this question is dumb, I'm sorry.

I don't know how to detect if it's the end of the input. For example, if I have a file called data.txt:

2 1 1
1 2 2
2 2 3
1 2 5

And a code main.mjs:

import { default as scanf, sscanf } from "scanf";

let a, b, c;
while(([a, b, c] = scanf("%d %d %d"))) { // don't know when to stop
        console.log(a, b, c);
}

After calling node main.mjs < data.txt

It results in infinite output:

2 1 1
1 2 2
2 2 3
1 2 5
2 1 1
1 2 2
2 2 3
1 2 5
2 1 1
1 2 2
2 2 3
1 2 5
// ... omitted

As the title, is there any way to detect that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions