Anonymous user
User input/Text: Difference between revisions
m
Fixed lang tags.
m (→{{header|JavaScript}}: spidermonkey's javascript implementation has print/readline) |
m (Fixed lang tags.) |
||
Line 4:
=={{header|Ada}}==
{{works with|GCC|4.1.2}}
<lang ada>function Get_String return String is
function Get_String return String is▼
▲ Line : String (1 .. 1_000);
▲ Last : Natural;
Get_Line (Line, Last);
▲ begin
return Line (1
▲ end Get_String;
▲ S : constant String := Get_String;
▲ begin
▲ return Integer'Value (S);
▲ -- may raise exception Constraint_Error if value entered is not a well-formed integer
▲ end Get_Integer;
</lang>▼
The functions above may be called as shown below
<lang ada>My_String : String := Get_String;
▲ My_Integer : Integer := Get_Integer;
</lang>▼
=={{header|ALGOL 68}}==
=={{header|AutoHotkey}}==
===Windows console===
<lang AutoHotkey>DllCall("AllocConsole")
FileAppend, please type something`n, CONOUT$
FileReadLine, line, CONIN$, 1
Line 70 ⟶ 65:
=={{header|AWK}}==
This demo shows a same-line prompt, and that the integer i becomes 0 if the line did not parse as an integer.
<lang awk>~/src/opt/run $ awk 'BEGIN{printf "enter a string: "}{s=$0;i=$0+0;print "ok,"s"/"i}'▼
<lang awk>▼
▲~/src/opt/run $ awk 'BEGIN{printf "enter a string: "}{s=$0;i=$0+0;print "ok,"s"/"i}'
enter a string: hello world
ok,hello world/0
75000
ok,75000/75000</lang>
=={{header|BASIC}}==
Line 92 ⟶ 85:
=={{header|Befunge}}==
This prompts for a string and pushes it to the stack a character at a time ('''~''') until end of input (-1).
Numeric input is easier, using the '''&''' command.
=={{header|C}}==
{{works with|gcc}}
<lang c>
=={{header|C++}}==
{{works with|g++}}
<lang cpp>
Note: The program as written above only reads the string up to the first whitespace character. To get a complete line into the string, replace
Line 143 ⟶ 136:
=={{header|C sharp|C#}}==
<lang csharp>
=={{header|Clojure}}==
<lang
(def scan (Scanner. *in*))
(def s (.nextLine scan))
(def n (.nextInt scan))</lang>
=={{header|Common Lisp}}==
Line 194 ⟶ 186:
=={{header|Erlang}}==
<lang erlang>
Alternatively, you could use io:get_line to get a string:
Line 202 ⟶ 194:
=={{header|FALSE}}==
FALSE has neither a string type nor numeric input. Shown instead are routines to parse and echo a word and to parse and interpret a number using the character input command (^).
=={{header|Forth}}==
===Input a string===
<lang forth>
===Input a number===
The only ANS standard number interpretation word is >NUMBER ( ud str len -- ud str len ), which is meant to be the base factor for more convenient (but non-standard) parsing words.
<lang forth>
{{works with|GNU Forth}}
<lang forth>
{{works with|Win32Forth}}
<lang forth>
Note that NUMBER? always leaves a double result on the stack.
Line 234 ⟶ 226:
Here is an example that puts it all together:
<lang forth>
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<lang fortran>character(20) :: s
integer :: i
Line 250 ⟶ 241:
read*, s
print*, "Enter the integer 75000"
read*, i</lang>
=={{header|Groovy}}==
<lang groovy>
=={{header|Haskell}}==
<lang haskell>import System.IO (hFlush, stdout)
import System.IO (hFlush, stdout)▼
▲ main = do
▲ putStr "Enter a string: "
str
putStr
▲ hFlush stdout
▲ num <- readLn :: IO Int
▲ putStrLn $ str ++ (show num)</lang>
Note: <tt>:: IO Int</tt> is only there to disambiguate what type we wanted from <tt>read</tt>. If <tt>num</tt> were used in a numerical context, its type would have been inferred by the interpreter/compiler.
Note also: Haskell doesn't automatically flush stdout when doing input, so explicit flushes are necessary.
=={{header|J}}==
▲ require 'misc' NB. load system script
▲ prompt 'Enter string: '
Both of these sentences return the user provided input. But this implementation implements no error checking: For example, if a different number is entered at the second prompt, it will be used instead of 75000.
=={{header|Java}}==
<lang java>
or
{{works with|Java|1.5/5.0+}}
<lang java>
=={{header|JavaScript}}==
Line 326 ⟶ 311:
=={{header|Logo}}==
Logo literals may be read from a line of input from stdin as either a list or a single word.
<lang logo>
=={{header|Mathematica}}==
<lang Mathematica>mystring = InputString["give me a string please"];
=={{header|Metafont}}==
Line 358 ⟶ 341:
=={{header|mIRC Scripting Language}}==
▲}</lang>
=={{header|Modula-3}}==
Line 376 ⟶ 359:
number := IO.GetInt();
IO.Put("You entered: " & string & " and " & Fmt.Int(number) & "\n");
END Input.</lang>
=={{header|newLISP}}==
{{works with|newLISP|9.0}}
=={{header|OCaml}}==
Line 414 ⟶ 396:
=={{header|Pascal}}==
<lang pascal>
=={{header|Perl}}==
{{works with|Perl|5.8.8}}
<lang perl>
=={{header|PHP}}==
{{works with|CLI SAPI}}
<lang php>
=={{header|Pop11}}==
<lang pop11>
=={{header|PostScript}}==
{{works with|PostScript|level-2}}
<lang postscript>
At this point there will be two items on the stack: a boolean which is "true" if the read was successful and the string that was read from the kbd (input terminates on a <return>). If the length of the string exceeds the buffer length, an error condition occurs (rangecheck). For the second part, the above could be followed by this:
<lang postscript>
which will read the conversion operator 'cvi' (convert to integer) and the boolean and execute the former if the latter is true.
Line 467 ⟶ 449:
=={{header|PowerShell}}==
<lang powershell>
=={{header|Python}}==
Line 489 ⟶ 471:
{{works with|R|2.81}}
<lang R>stringval <- readline("String: ")
=={{header|Raven}}==
<lang raven>
=={{header|REXX}}==
Line 506 ⟶ 486:
=={{header|Ruby}}==
{{works with|Ruby|1.8.4}}
<lang ruby>
=={{header|Scheme}}==
The <tt>read</tt> procedure is R5RS standard, inputs a scheme representation so, in order to read a string, one must enter <tt>"hello world"</tt>
<lang scheme>
=={{header|Slate}}==
<lang slate>print: (query: 'Enter a String: ').
[| n |
n: (Integer readFrom: (query: 'Enter an Integer: ')).
Line 528 ⟶ 507:
ifTrue: [print: n]
ifFalse: [inform: 'Not an integer: ' ; n printString]
] do.</lang>
=={{header|Smalltalk}}==
Line 580 ⟶ 558:
This program leaves the requested values in the global variables ''s'' and ''integer''.
InputStr "Enter a string", s
Loop
Line 590 ⟶ 568:
EndIf
EndLoop
EndPrgm</
=={{header|Toka}}==
=={{header|UNIX Shell}}==
{{works with|Debian Almquish SHell}}
{{works with|Bourne Again SHell}}
=={{header|Vedit macro language}}==
=={{header|Visual Basic .NET}}==
|