Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 3e60ff9d4d6f58c8fbd17208f14089fa > files > 408

octave-doc-3.2.3-3mdv2010.0.i586.rpm

<html lang="en">
<head>
<title>Terminal Input - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Basic-Input-and-Output.html#Basic-Input-and-Output" title="Basic Input and Output">
<link rel="prev" href="Terminal-Output.html#Terminal-Output" title="Terminal Output">
<link rel="next" href="Simple-File-I_002fO.html#Simple-File-I_002fO" title="Simple File I/O">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Terminal-Input"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Simple-File-I_002fO.html#Simple-File-I_002fO">Simple File I/O</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Terminal-Output.html#Terminal-Output">Terminal Output</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Basic-Input-and-Output.html#Basic-Input-and-Output">Basic Input and Output</a>
<hr>
</div>

<h4 class="subsection">14.1.2 Terminal Input</h4>

<p>Octave has three functions that make it easy to prompt users for
input.  The <code>input</code> and <code>menu</code> functions are normally
used for managing an interactive dialog with a user, and the
<code>keyboard</code> function is normally used for doing simple debugging.

<!-- input.cc -->
   <p><a name="doc_002dinput"></a>

<div class="defun">
&mdash; Built-in Function:  <b>input</b> (<var>prompt</var>)<var><a name="index-input-722"></a></var><br>
&mdash; Built-in Function:  <b>input</b> (<var>prompt, "s"</var>)<var><a name="index-input-723"></a></var><br>
<blockquote><p>Print a prompt and wait for user input.  For example,

     <pre class="example">          input ("Pick a number, any number! ")
</pre>
        <p class="noindent">prints the prompt

     <pre class="example">          Pick a number, any number!
</pre>
        <p class="noindent">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 expression.

        <p>Currently, <code>input</code> only returns one value, regardless of the number
of values produced by the evaluation of the expression.

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

        <p>Because there may be output waiting to be displayed by the pager, it is
a good idea to always call <code>fflush (stdout)</code> before calling
<code>input</code>.  This will ensure that all pending output is written to
the screen before your prompt.  See <a href="Input-and-Output.html#Input-and-Output">Input and Output</a>. 
</p></blockquote></div>

<!-- ./miscellaneous/menu.m -->
   <p><a name="doc_002dmenu"></a>

<div class="defun">
&mdash; Function File:  <b>menu</b> (<var>title, opt1, <small class="dots">...</small></var>)<var><a name="index-menu-724"></a></var><br>
<blockquote><p>Print a title string followed by a series of options.  Each option will
be printed along with a number.  The return value is the number of the
option selected by the user.  This function is useful for interactive
programs.  There is no limit to the number of options that may be passed
in, but it may be confusing to present more than will fit easily on one
screen. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002ddisp.html#doc_002ddisp">disp</a>, <a href="doc_002dprintf.html#doc_002dprintf">printf</a>, <a href="doc_002dinput.html#doc_002dinput">input</a>. 
</p></blockquote></div>

<!-- input.cc -->
   <p><a name="doc_002dyes_005for_005fno"></a>

<div class="defun">
&mdash; Built-in Function:  <b>yes_or_no</b> (<var>prompt</var>)<var><a name="index-yes_005for_005fno-725"></a></var><br>
<blockquote><p>Ask the user a yes-or-no question.  Return 1 if the answer is yes. 
Takes one argument, which is the string to display to ask the
question.  It should end in a space; &lsquo;<samp><span class="samp">yes-or-no-p</span></samp>&rsquo; adds
&lsquo;<samp><span class="samp">(yes or no) </span></samp>&rsquo; to it.  The user must confirm the answer with
RET and can edit it until it has been confirmed. 
</p></blockquote></div>

   <p>For <code>input</code>, the normal command line history and editing functions
are available at the prompt.

   <p>Octave also has a function that makes it possible to get a single
character from the keyboard without requiring the user to type a
carriage return.

<!-- sysdep.cc -->
   <p><a name="doc_002dkbhit"></a>

<div class="defun">
&mdash; Built-in Function:  <b>kbhit</b> ()<var><a name="index-kbhit-726"></a></var><br>
<blockquote><p>Read a single keystroke from the keyboard.  If called with one
argument, don't wait for a keypress.  For example,

     <pre class="example">          x = kbhit ();
</pre>
        <p class="noindent">will set <var>x</var> to the next character typed at the keyboard as soon as
it is typed.

     <pre class="example">          x = kbhit (1);
</pre>
        <p class="noindent">identical to the above example, but don't wait for a keypress,
returning the empty string if no key is available. 
</p></blockquote></div>

   </body></html>