Input/Output for lines of text: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (added a ;Task: and ;Related task: (bold) headers, added other whitespace to the task's preamble.)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(47 intermediate revisions by 31 users not shown)
Line 1:
{{draft task}}
{{clarify task}}
 
;Task:
Line 29 ⟶ 30:
*   [[File/Input and Output]]
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">F do_stuff(words)
print(words)
 
V linecount = Int(input())
L 1..linecount
V line = input()
do_stuff(line)</syntaxhighlight>
 
=={{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}}
<syntaxhighlight lang="action!">CARD EndProg ;required for ALLOCATE.ACT
 
INCLUDE "D2:ALLOCATE.ACT" ;from the Action! Tool Kit. You must type 'SET EndProg=*' from the monitor after compiling, but before running this program!
 
PROC Main()
DEFINE PTR="CARD"
BYTE i,nLines
PTR ARRAY lines(256)
CHAR ARRAY line(256),p
 
AllocInit(0)
Put(125) PutE()
 
nLines=InputB()
IF nLines=0 THEN RETURN FI
 
FOR i=0 TO nLines-1
DO
InputS(line)
p=Alloc(line(0)+1)
MoveBlock(p,line,line(0)+1)
lines(i)=p
OD
 
PutE()
FOR i=0 TO nLines-1
DO
p=lines(i)
PrintE(p)
OD
 
FOR i=0 TO nLines-1
DO
p=lines(i)
Free(p,p(0)+1)
lines(i)=0
OD
nLines=0
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Input_Output_for_lines_of_text.png Screenshot from Atari 8-bit computer]
<pre>
3
hello
hello world
Pack my Box with 5 dozen liquor jugs
 
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
 
=={{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.
--
-- Write to STDOUT each line of input by passing it to a method as an
-- intermediate step. The code should demonstrate these 3 things.
--
 
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
 
procedure Main is
Num_Lines : Integer;
begin
Get(Num_Lines);
Skip_Line;
for I in 1..Num_Lines loop
Put_Line(Get_Line);
end loop;
end Main;
</syntaxhighlight>
'''Input:'''
<pre>
3
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
{{output}}
<pre>
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.win32}}
<langsyntaxhighlight lang="algol68"># outputs line plus a newline #
PROC show line = ( STRING line )VOID:
print( ( line, newline ) );
Line 43 ⟶ 146:
show line( ( STRING line; read( ( line, newline ) ); line ) )
OD
</syntaxhighlight>
</lang>
 
=={{header|CALGOL W}}==
<syntaxhighlight lang="algolw">begin
<lang C>
% outputs line on a newline %
/*Abhishek Ghosh, 20th March 2014, Rotterdam*/
procedure showLine ( string(80) value line ); write( line );
 
string(80) line;
integer lineCount;
read( lineCount );
for lineNumber := 1 until lineCount do begin
read( line );
showLine( line )
end for_lineNumber
end.</syntaxhighlight>
 
=={{header|Applesoft BASIC}}==
<syntaxhighlight lang="gwbasic"> 100 GOSUB 230"INPUT LINE"
110 LET N = VAL (L$) - 1
120 IF N < 0 THEN END
130 DIM L$(N)
140 FOR I = 0 TO N
150 GOSUB 230"INPUT LINE"
160 LET L$(I) = L$
170 NEXT I
190 FOR I = 0 TO N
200 PRINT L$(I)
210 NEXT
220 END
230 LET L$ = ""
240 LET C$ = ""
250 FOR C = 0 TO 1 STEP 0
260 LET L$ = L$ + C$
270 GET C$
280 PRINT CHR$ (0)C$;
290 LET C = C$ = CHR$ (13)
300 NEXT C
310 LET C = FRE (0)
320 RETURN</syntaxhighlight>
'''Input'''
<pre>
3
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
{{out}}
<pre>
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">printLine: function [line]-> print line
 
lineCount: to :integer strip input ""
 
do.times:lineCount [
line: input ""
printLine line
]</syntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f INPUT_OUTPUT_FOR_LINES_OF_TEXT.AWK
BEGIN {
getline n
while (i++ < n) {
getline
str = sprintf("%s%s\n",str,$0)
}
printf("%s",str)
exit(0)
}
</syntaxhighlight>
 
=={{header|Batch File}}==
<syntaxhighlight lang="dos">
@echo off
setlocal enabledelayedexpansion
 
set /p lines=
 
for /l %%i in (1,1,%lines%) do set /p line%%i=
cls
for /l %%i in (1,1,%lines%) do echo !line%%i!
pause>nul
</syntaxhighlight>
{{in}}
<pre>
3
line 1
this is line 2
line 3 is the longest
</pre>
{{out}}
<pre>
line 1
this is line 2
line 3 is the longest
</pre>
 
=={{header|C}}==
<syntaxhighlight lang="c">
#include<stdlib.h>
#include<stdio.h>
Line 79 ⟶ 281:
return 0;
}
</syntaxhighlight>
</lang>
 
Alternative code:
 
This program will read a number through STDIN... well, trough pipeline:
 
$ echo n | io
 
where "n" is the number of lines it will print.
 
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>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
 
int check_number(const char *s){
const char*t=s;
while(*t!='\n'){
if( !isdigit(*t) ) return 0;
++t;
}
return 1;
}
int main( int argc, char *argv[] )
{
char s[100],r[10];
int n=0;
FILE *fp;
fgets(s,100,stdin); // input trough stdin.
if( (fp = fopen("temporal.txt","r"))!=NULL){
fgets(r,10,fp);
n=atoi(r);
if(n>0){
--n;
fclose(fp);
fp=fopen("temporal.txt","w");
sprintf(r,"%d",n);
fputs(r,fp);
fclose(fp);
printf("%s\n",s);
}else{
fclose(fp);
remove("temporal.txt");
perror("I need a number of the lines here!\n");
}
}else{
if(check_number((const char*)s)){
fp=fopen("temporal.txt","w");
fputs(s,fp);
fclose(fp);
}else{
perror("I need a number of the lines here!\n");
}
}
return 0;
}
</syntaxhighlight>
{{out}}
<pre>
$ echo 3 | ./io
$ echo "hola" | ./io
hola
 
$ echo "hola mundo" | ./io
hola mundo
 
$ echo "lore ipsum et la concha de la lora latinus" | ./io
lore ipsum et la concha de la lora latinus
 
$ echo "lore ipsum et la concha de la lora latinus" | ./io
I need a number of the lines here!
: Success
$
</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <iostream>
#include <vector>
 
int main()
{
// read the number of lines
int numberOfLines;
std::cin >> numberOfLines;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // skip to next line
// read the lines
std::vector<std::string> lines(numberOfLines);
for(int i = 0; i < numberOfLines; ++i)
{
std::getline(std::cin, lines[i]);
}
 
// print the lines
for(const auto& value : lines)
{
std::cout << value << "\n";
}
}</syntaxhighlight>
'''Input:'''
<pre>
3
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
{{out}}
<pre>
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
 
=={{header|D}}==
<langsyntaxhighlight lang="d">void main() {
import std.stdio, std.conv, std.string;
 
Line 89 ⟶ 408:
foreach (_; 0 .. readln.strip.to!uint)
doStuff(readln.idup);
}</langsyntaxhighlight>
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
<syntaxhighlight lang="delphi">
program Output_for_Lines_of_Text;
 
{$APPTYPE CONSOLE}
 
uses
System.SysUtils;
 
function QueryIntNumber(): Integer;
var
val: string;
begin
Result := 0;
repeat
Writeln('Digite a number(Enter to confirm):');
Readln(val);
 
if not TryStrToInt(val, Result) then
begin
Writeln('"', val, '" is not a valid number.');
Continue;
end;
if Result <= 0 then
begin
Writeln('"', val, '" must be greater then 0');
Continue;
end;
until Result > 0;
end;
 
var
n_lines, i: integer;
lines, line: string;
 
begin
lines := '';
n_lines := QueryIntNumber;
 
for i := 1 to n_lines do
begin
Readln(line);
if i > 1 then
lines := lines + #10;
lines := lines + line;
end;
 
Writeln(lines);
Readln;
end.</syntaxhighlight>
{{out}}
<pre>
Digite a number(Enter to confirm):
3
hello
hello world
Pack my Box with 5 dozen liquor jugs
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: io kernel strings ;
IN: input-output
 
GENERIC: do-stuff ( obj -- )
M: string do-stuff print ;
 
readln drop [ do-stuff ] each-line</syntaxhighlight>
 
=={{header|Free Pascal}}==
This requires FPC – the FreePascal compiler – to be in a configuration enabling the use ob <tt>object</tt>s.
<syntaxhighlight lang="pascal">program head(input, output, stdErr);
 
type
obj = object
public
procedure method(const s: string); static;
end;
 
procedure obj.method(const s: string);
begin
writeLn(s);
end;
 
var
numberOfLines: integer;
line: string;
begin
readLn(numberOfLines);
for numberOfLines := numberOfLines downto 1 do
begin
readLn(line);
obj.method(line);
end;
end.</syntaxhighlight>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Sub printLines(lines() As String)
For i As Integer = LBound(lines) To UBound(lines)
Print lines(i)
Next
End Sub
 
Dim As UInteger n
Input "", n
Dim lines(1 To n) As String
For i As Integer = 1 To n
Line Input lines(i)
Next
Print
printLines lines()
Sleep</syntaxhighlight>
 
{{out}}
<pre>
3
hello
hello world
Pack my Box with 5 dozen liquor jugs
 
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 143 ⟶ 592:
func doStuff(line string) {
fmt.Println(line)
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">import Control.Monad
main = do
number <- getLine
input <- replicateM (read number) getLine
mapM_ putStrLn input
</syntaxhighlight>'''Input:'''
<pre>
3
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
{{out}}
<pre>
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
 
=={{header|J}}==
Line 149 ⟶ 618:
 
Example in bash. jconsole is on the PATH.
<syntaxhighlight lang="j">
<lang J>
$ cat <<EOF | jconsole -js '2!:55@:0:@:(; (1!:2) 4:)@:(}. {.~ _ ". [: }: 0&{::)@:(<;.2)@:(1!:1) 3'
> 3
Line 159 ⟶ 628:
hello world
Pack my Box with 5 dozen liquor jugs
</syntaxhighlight>
</lang>
From the dictionary of j (DOJ) the data flow for the fork (f g h) is
 
Line 211 ⟶ 680:
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">import java.util.Scanner;
 
public class Main {
Line 226 ⟶ 695:
}
}
}</langsyntaxhighlight>
 
=={{header|jq}}==
The following works for both the C and the Go implementations of jq.
<pre>
jq -Rr 'limit(tonumber; inputs)'
</pre>
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
 
<syntaxhighlight lang="julia">function dosomething(words)
print(words)
end
 
nlines = parse.(Int, readline())
for _ in 1:nlines
words = readline()
dosomething(words)
end</syntaxhighlight>
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scala">// version 1.1
 
fun output(lines: Array<String>) = println(lines.joinToString("\n"))
 
fun main(args: Array<String>) {
println("Enter the number of lines to be input followed by those lines:\n")
val n = readLine()!!.toInt()
val lines = Array(n) { readLine()!! }
println("\nThe lines you entered are:\n")
output(lines)
}</syntaxhighlight>
 
{{out}}
<pre>
Enter the number of lines to be input followed by those lines:
 
3
hello
hello world
Pack my Box with 5 dozen liquor jugs
 
The lines you entered are:
 
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">function show (t)
for _, line in pairs(t) do print(line) end
end
Line 235 ⟶ 752:
local lineTable, numLines = {}, io.read()
for i = 1, numLines do table.insert(lineTable, io.read()) end
show(lineTable)</langsyntaxhighlight>
 
=={{header|Nanoquery}}==
{{trans|Ursa}}
<syntaxhighlight lang="nanoquery">// get how many lines the user wants
amount = int(input())
 
// loop through and get lines
lines = {}
for i in range(1, amount)
lines.append(input())
end
 
// output the lines that the user entered
println
for line in lines
println line
end</syntaxhighlight>
{{out}}
<pre>3
this is a test
the program will read three lines from the console
this is the third line
 
this is a test
the program will read three lines from the console
this is the third line</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import strutils
 
proc write(line: string) =
echo line
 
let lineCount = stdin.readLine.parseInt()
for _ in 1..lineCount:
let line = stdin.readLine()
line.write()</syntaxhighlight>
 
=={{header|Objeck}}==
<syntaxhighlight lang="objeck">use System.IO.File;
 
class Rosetta {
function : Main(args : String[]) ~ Nil {
in : FileReader;
leaving {
if(in <> Nil) {
in->Close();
};
};
if(args->Size() = 1) {
in := FileReader->New(args[0]);
i := in->ReadString()->ToInt();
while(i-- <> 0) {
in->ReadString()->PrintLine();
};
};
}
}</syntaxhighlight>
 
=={{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:
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <pari/pari.h>
Line 265 ⟶ 841:
pari_printf("%Ps", vec);
return 0;
}</langsyntaxhighlight>
 
=={{header|Perl 6}}==
<syntaxhighlight lang="perl">$n = scalar <>;
<lang perl6>$*OUT.say($*IN.get) xx $*IN.get;</lang>
 
do_stuff(scalar <>) for 1..$n;
 
sub do_stuff { print $_[0] }</syntaxhighlight>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(notonline)-->
<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>
<span style="color: #008080;">procedure</span> <span style="color: #7060A8;">push</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">line</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">stack</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">stack</span><span style="color: #0000FF;">,</span><span style="color: #000000;">line</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">pop_all</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">while</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">stack</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<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: #000000;">stack</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">])</span>
<span style="color: #000000;">stack</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">stack</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..$]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">line</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">gets</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">scanf</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">trim</span><span style="color: #0000FF;">(</span><span style="color: #000000;">line</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"%d"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
<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;">"input not a number\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">abort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<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: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">line</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">gets</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">push</span><span style="color: #0000FF;">(</span><span style="color: #000000;">line</span><span style="color: #0000FF;">)</span>
<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: #008080;">end</span> <span style="color: #008080;">for</span>
<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>
<!--</syntaxhighlight>-->
{{out}}
(or more accurately the final state of the console)
<pre>
3
one
two
three
===
one
two
three
</pre>
 
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
<lang PowerShell>
# script.ps1
 
Line 278 ⟶ 901:
 
# ./script file.txt
</syntaxhighlight>
</lang>
 
=={{header|Prolog}}==
<syntaxhighlight lang="prolog">
number_of_lines(Num) :-
current_input(In),
read_line_to_codes(In, Line),
number_codes(Num, Line).
input_lines_for_num(0, ListOfLines) :-
format('~nThe lines you entered were: ~n~n'),
maplist(format('~w~n'), ListOfLines).
input_lines_for_num(Num, CurrentLines) :-
Num > 0,
Num1 is Num - 1,
current_input(In),
read_line_to_codes(In, Line),
atom_codes(LineAsAtom, Line),
append(CurrentLines, [LineAsAtom], MoreLines),
input_lines_for_num(Num1, MoreLines).
lines :-
number_of_lines(Num),
input_lines_for_num(Num, []).
</syntaxhighlight>
{{out}}
<pre>
2 ?- lines.
|: 3
line 1
line 2
line 3
 
The lines you entered were:
 
line 1
line 2
line 3
true ;
false.
 
3 ?-
</pre>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">try: input = raw_input
except: pass
 
Line 290 ⟶ 955:
for x in range(linecount):
line = input()
do_stuff(line)</langsyntaxhighlight>
 
=={{header|Racket}}==
{{trans|Python}}
<langsyntaxhighlight Racketlang="racket">#lang racket
(define (do-stuff str)
(displayln str))
Line 305 ⟶ 970:
 
(for ([i (in-range line-count)])
(do-stuff (read-line)))</langsyntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
 
Short version:
 
<syntaxhighlight lang="raku" line>say get for ^get;</syntaxhighlight>
 
Verbose version:
 
<syntaxhighlight lang="raku" line>sub do-stuff ($line) {
say $line;
}
my $n = +get;
for ^$n {
my $line = get;
do-stuff $line;
}</syntaxhighlight>
 
=={{header|REXX}}==
Programming note: &nbsp; this method was chosen because the standard input may be identical to the standard output.
<langsyntaxhighlight lang="rexx">/*REXX program writes a number of lines from the default input file (C.L.). */
#=linein() /*number of lines to be read from C.L. */
 
Line 317 ⟶ 1,001:
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
stuff: do k=1 for #; call lineout ,x.k; end; return</langsyntaxhighlight>
{{out|output|text=&nbsp; where showing the input and the output to the terminal:}}
<pre>
3 ◄■■■■■■■ user input
aaa ◄■■■■■■■ user input
bbb ◄■■■■■■■ user input
ccc ◄■■■■■■■ user input
aaa
bbb
ccc
</pre>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
# Project : Input/Output for Lines of Text
 
see "n = "
give n
lines = list(number(n))
for i = 1 to n
see "lines[" + i + "] = " + nl
give lines[i]
next
see nl
printlines(lines)
 
func printlines(lines)
for i = 1 to len(lines)
see lines[i] + nl
next
</syntaxhighlight>
Input:
<pre>
3
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
Output:
<pre>
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">def do_stuff(line)
puts line
end
Line 328 ⟶ 1,055:
line = gets
do_stuff(line)
end</langsyntaxhighlight>
 
=={{header|Scala}}==
<syntaxhighlight lang="scala">// Input/Output for Lines of Text
object IOLines extends App {
private val in = scala.io.StdIn
private val n = in.readInt()
 
private def doStuff(word: String): Unit = println(word)
 
for (_ <- 0 until n) {
val word = in.readLine()
doStuff(word)
}
}</syntaxhighlight>
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">proc do_stuff {line} {
puts $line
}
Line 337 ⟶ 1,078:
foreach - [lrepeat [gets stdin] dummy] {
do_stuff [gets stdin]
}</langsyntaxhighlight>
 
=={{header|Ursa}}==
<langsyntaxhighlight lang="ursa">#
# input/output for lines of text
#
Line 360 ⟶ 1,101:
out lines<i> endl console
end for
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
This assumes that both Stdin and Stdout are connected to a terminal.
<syntaxhighlight lang="wren">import "io" for Stdin
 
var output = Fn.new { |lines| System.print(lines.join("\n")) }
 
var n = Num.fromString(Stdin.readLine())
if (!n || !n.isInteger || n < 1) Fiber.abort("Number of lines must be a positive integer.")
var lines = List.filled(n, "")
for (i in 0...n) lines[i] = Stdin.readLine()
System.print()
output.call(lines)</syntaxhighlight>
 
{{out}}
Sample input/output:
<pre>
3
hello
hello world
Pack my Box with 5 dozen liquor jugs
 
hello
hello world
Pack my Box with 5 dozen liquor jugs
</pre>
 
=={{header|XPL0}}==
The input file must be redirected on the command line, for example: iotext <iotext.txt
<syntaxhighlight lang="xpl0">string 0;
 
proc PrintLn(Str); \"method" to print a line of text
char Str;
[Text(0, Str);
CrLf(0);
];
 
char Line(1000);
int N, I, C;
for N:= 1 to IntIn(1) do
[I:= 0;
loop [repeat C:= ChIn(1) until C # $0D \CR\;
if C = $0A \LF\ then quit;
Line(I):= C;
I:= I+1;
];
Line(I):= 0;
PrintLn(Line);
]</syntaxhighlight>
 
=={{header|zkl}}==
File ff.zkl:
<langsyntaxhighlight lang="zkl">numLines:=File.stdin.readln().strip().toInt();
text:=File.stdin.readln(numLines);
 
text.apply(File.stdout.write);</langsyntaxhighlight>
{{out}}
<pre>
9,476

edits