What is some Chapel code that is equivalent to C's fgets function?
`fgets(buffer, sizeof(buffer), stdin)`
The above call to fgets reads data from stdin until a newline character is encountered. The Chapel readln function stops reading when whitespace is encountered. I want readln to read until a newline character is encountered. There is iostringformat.toend that appears to be the solution, but how do I get stdin to behave as if that is enabled?
Use readline instead of readln. See https://chapel-lang.org/docs/modules/standard/IO.html#IO.channel.readline
Try this program for example:
config const fname = "test.txt";
var r = openreader(fname);
var line:string;
while r.readline(line) {
write("I just read: ", line);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With