RosettaCodeData/Task/User-input-Text/Neko/user-input-text.neko

36 lines
940 B
Plaintext

/**
User input/Text, in Neko
Tectonics:
nekoc userinput.neko
neko userinput
*/
var stdin = $loader.loadprim("std@file_stdin", 0)()
var file_read_char = $loader.loadprim("std@file_read_char", 1)
/* Read a line from file f into string s returning length without any newline */
var NEWLINE = 10
var readline = function(f, s) {
var len = 0
var ch
while true {
try ch = file_read_char(f) catch a break;
if ch == NEWLINE break;
if $sset(s, len, ch) == null break; else len += 1
}
return $ssub(s, 0, len)
}
$print("Enter a line of text, then the number 75000\n")
try {
var RECL = 132
var str = $smake(RECL)
var userstring = readline(stdin, str)
$print(":", userstring, ":\n")
var num = $int(readline(stdin, str))
if num == 75000 $print("Rosetta Code 75000, for the win!\n")
else $print("Sorry, need 75000\n")
} catch problem $print("Exception: ", problem, "\n")