Navigation

Operators and Keywords

Function List:

C++ API

: ans = input (prompt)
: ans = input (prompt, "s")

Print prompt and wait for user input.

For example,

input ("Pick a number, any number! ")

prints the prompt

Pick a number, any number!

and waits for the user to enter a value. The string entered by the user is evaluated as an expression, so it may be a literal constant, a variable name, or any other valid Octave code.

The number of return arguments, their size, and their class depend on the expression entered.

If you are only interested in getting a literal string value, you can call input with the character string "s" as the second argument. This tells Octave to return the string entered by the user directly, without evaluating it first.

Because there may be output waiting to be displayed by the pager, it is a good idea to always call fflush (stdout) before calling input. This will ensure that all pending output is written to the screen before your prompt.

See also: yes_or_no, kbhit, pause, menu, listdlg.

Package: octave