On 5/19/07, Terrence Brannon <[EMAIL PROTECTED]> wrote:
I want to write a simple program which:
   * read integers from stdin, one line at a time
   * print the sum of those integers

What OS?

For unix, the first line of your script should be something like:
#!/usr/local/j601/jconsole

Anyways, under windows you've got a different problem:
stdin isnt' very std, under windows.  For me, I was able
to read from the stdin file descriptor, but I could not use
stdin interactively, and I got the whole thing all at once
(not a line at a time).

Anyways, this worked for me:

9!:29]1[9!:27'exit 1'
3 :0''
sum=. 0
while.#line=:1!:1]3 do.
 sum=.sum++/0".' ' (I.line e.CRLF)} line
end.
echo sum
)
exit 0



I ran this from a cygwin shell, as:

  (echo 1; echo 2; echo 3) | ./jconsole test.ijs

And it displayed 6 as its result.

Note that some parts of my program aren't
really used here (I only go through that loop
once).  I left the loop in place, in case behavior
of stdin is different on some other system (like
maybe linux or mac).

FYI,

--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to