Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent Chapel functionality for C fgets function

Tags:

io

chapel

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?

like image 752
tmacd8 Avatar asked Dec 07 '25 18:12

tmacd8


1 Answers

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);
}
like image 175
mppf Avatar answered Dec 09 '25 19:12

mppf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!