Input/Output for lines of text: Difference between revisions
m
syntax highlighting fixup automation
(Applesoft BASIC) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 34:
{{trans|Python}}
<
print(words)
Line 40:
L 1..linecount
V line = input()
do_stuff(line)</
=={{header|Action!}}==
The user must type in the monitor the following command after compilation and before running the program!<pre>SET EndProg=*</pre>
{{libheader|Action! Tool Kit}}
<
INCLUDE "D2:ALLOCATE.ACT" ;from the Action! Tool Kit. You must type 'SET EndProg=*' from the monitor after compiling, but before running this program!
Line 83:
OD
nLines=0
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Input_Output_for_lines_of_text.png Screenshot from Atari 8-bit computer]
Line 98:
=={{header|Ada}}==
<syntaxhighlight lang="ada">--
-- The first line contains the number of lines to follow, followed by that
-- number of lines of text on STDIN.
Line 118:
end loop;
end Main;
</syntaxhighlight>
'''Input:'''
<pre>
Line 135:
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.win32}}
<
PROC show line = ( STRING line )VOID:
print( ( line, newline ) );
Line 146:
show line( ( STRING line; read( ( line, newline ) ); line ) )
OD
</syntaxhighlight>
=={{header|ALGOL W}}==
<
% outputs line on a newline %
procedure showLine ( string(80) value line ); write( line );
Line 160:
showLine( line )
end for_lineNumber
end.</
=={{header|Applesoft BASIC}}==
<
110 LET N = VAL (L$) - 1
120 IF N < 0 THEN END
Line 184:
300 NEXT C
310 LET C = FRE (0)
320 RETURN</
'''Input'''
<pre>
Line 199:
</pre>
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f INPUT_OUTPUT_FOR_LINES_OF_TEXT.AWK
BEGIN {
Line 210:
exit(0)
}
</syntaxhighlight>
=={{header|Batch File}}==
<
@echo off
setlocal enabledelayedexpansion
Line 223:
for /l %%i in (1,1,%lines%) do echo !line%%i!
pause>nul
</syntaxhighlight>
{{in}}
<pre>
Line 239:
=={{header|C}}==
<syntaxhighlight lang="c">
#include<stdlib.h>
#include<stdio.h>
Line 270:
return 0;
}
</syntaxhighlight>
Alternative code:
Line 282:
When the total number of lines entered has been reached, it will display a message indicating that you must enter a number.
<syntaxhighlight lang="c">
// Programa IO.C
#include <stdio.h>
Line 332:
return 0;
}
</syntaxhighlight>
{{out}}
<pre>
Line 352:
=={{header|C++}}==
<
#include <vector>
Line 374:
std::cout << value << "\n";
}
}</
'''Input:'''
<pre>
Line 390:
=={{header|D}}==
<
import std.stdio, std.conv, std.string;
Line 397:
foreach (_; 0 .. readln.strip.to!uint)
doStuff(readln.idup);
}</
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
<syntaxhighlight lang="delphi">
program Output_for_Lines_of_Text;
Line 448:
Writeln(lines);
Readln;
end.</
{{out}}
<pre>
Line 462:
=={{header|Factor}}==
<
IN: input-output
Line 468:
M: string do-stuff print ;
readln drop [ do-stuff ] each-line</
=={{header|Free Pascal}}==
This requires FPC – the FreePascal compiler – to be in a configuration enabling the use ob <tt>object</tt>s.
<
type
Line 496:
obj.method(line);
end;
end.</
=={{header|FreeBASIC}}==
<
Sub printLines(lines() As String)
Line 515:
Print
printLines lines()
Sleep</
{{out}}
Line 530:
=={{header|Go}}==
<
import (
Line 581:
func doStuff(line string) {
fmt.Println(line)
}</
=={{header|Haskell}}==
<
main = do
number <- getLine
input <- replicateM (read number) getLine
mapM_ putStrLn input
</
<pre>
3
Line 607:
Example in bash. jconsole is on the PATH.
<syntaxhighlight lang="j">
$ cat <<EOF | jconsole -js '2!:55@:0:@:(; (1!:2) 4:)@:(}. {.~ _ ". [: }: 0&{::)@:(<;.2)@:(1!:1) 3'
> 3
Line 617:
hello world
Pack my Box with 5 dozen liquor jugs
</syntaxhighlight>
From the dictionary of j (DOJ) the data flow for the fork (f g h) is
Line 669:
=={{header|Java}}==
<
public class Main {
Line 684:
}
}
}</
=={{header|Julia}}==
{{works with|Julia|0.6}}
<
print(words)
end
Line 697:
words = readline()
dosomething(words)
end</
=={{header|Kotlin}}==
<
fun output(lines: Array<String>) = println(lines.joinToString("\n"))
Line 710:
println("\nThe lines you entered are:\n")
output(lines)
}</
{{out}}
Line 729:
=={{header|Lua}}==
<
for _, line in pairs(t) do print(line) end
end
Line 735:
local lineTable, numLines = {}, io.read()
for i = 1, numLines do table.insert(lineTable, io.read()) end
show(lineTable)</
=={{header|Nanoquery}}==
{{trans|Ursa}}
<
amount = int(input())
Line 752:
for line in lines
println line
end</
{{out}}
<pre>3
Line 764:
=={{header|Nim}}==
<
proc write(line: string) =
Line 772:
for _ in 1..lineCount:
let line = stdin.readLine()
line.write()</
=={{header|Objeck}}==
<
class Rosetta {
Line 794:
};
}
}</
=={{header|PARI/GP}}==
This task is not possible to implement directly in GP: for <code>input()</code> to take a string the user would have to wrap it in quotes (and escape quotes and newlines). One must use PARI:
<
#include <stdlib.h>
#include <pari/pari.h>
Line 824:
pari_printf("%Ps", vec);
return 0;
}</
=={{header|Perl}}==
<
do_stuff(scalar <>) for 1..$n;
sub do_stuff { print $_[0] }</
=={{header|Phix}}==
<!--<
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">stack</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
Line 862:
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"===\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">pop_all</span><span style="color: #0000FF;">()</span>
<!--</
{{out}}
(or more accurately the final state of the console)
Line 877:
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
# script.ps1
Line 884:
# ./script file.txt
</syntaxhighlight>
=={{header|Prolog}}==
<syntaxhighlight lang="prolog">
number_of_lines(Num) :-
current_input(In),
Line 908:
number_of_lines(Num),
input_lines_for_num(Num, []).
</syntaxhighlight>
{{out}}
<pre>
Line 929:
=={{header|Python}}==
<
except: pass
Line 938:
for x in range(linecount):
line = input()
do_stuff(line)</
=={{header|Racket}}==
{{trans|Python}}
<
(define (do-stuff str)
(displayln str))
Line 953:
(for ([i (in-range line-count)])
(do-stuff (read-line)))</
=={{header|Raku}}==
Line 960:
Short version:
<syntaxhighlight lang="raku"
Verbose version:
<syntaxhighlight lang="raku"
say $line;
}
Line 972:
my $line = get;
do-stuff $line;
}</
=={{header|REXX}}==
Programming note: this method was chosen because the standard input may be identical to the standard output.
<
#=linein() /*number of lines to be read from C.L. */
Line 984:
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
stuff: do k=1 for #; call lineout ,x.k; end; return</
{{out|output|text= where showing the input and the output to the terminal:}}
<pre>
Line 997:
=={{header|Ring}}==
<
# Project : Input/Output for Lines of Text
Line 1,014:
see lines[i] + nl
next
</syntaxhighlight>
Input:
<pre>
Line 1,030:
=={{header|Ruby}}==
<
puts line
end
Line 1,038:
line = gets
do_stuff(line)
end</
=={{header|Scala}}==
<
object IOLines extends App {
private val in = scala.io.StdIn
Line 1,052:
doStuff(word)
}
}</
=={{header|Tcl}}==
<
puts $line
}
Line 1,061:
foreach - [lrepeat [gets stdin] dummy] {
do_stuff [gets stdin]
}</
=={{header|Ursa}}==
<
# input/output for lines of text
#
Line 1,084:
out lines<i> endl console
end for
</syntaxhighlight>
=={{header|Wren}}==
This assumes that both Stdin and Stdout are connected to a terminal.
<
var output = Fn.new { |lines| System.print(lines.join("\n")) }
Line 1,097:
for (i in 0...n) lines[i] = Stdin.readLine()
System.print()
output.call(lines)</
{{out}}
Line 1,114:
=={{header|XPL0}}==
The input file must be redirected on the command line, for example: iotext <iotext.txt
<
proc PrintLn(Str); \"method" to print a line of text
Line 1,133:
Line(I):= 0;
PrintLn(Line);
]</
=={{header|zkl}}==
File ff.zkl:
<
text:=File.stdin.readln(numLines);
text.apply(File.stdout.write);</
{{out}}
<pre>
|