home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / RLaB 1.15c / rlib / input.r < prev    next >
Encoding:
Text File  |  1994-10-09  |  1.1 KB  |  43 lines  |  [TEXT/RLAB]

  1. //-------------------------------------------------------------------//
  2.  
  3. //  Syntax:    input ( STRING )
  4. //        input ( STRING , "s" )
  5.  
  6. //  Description:
  7.  
  8. //  The input function provides an easy method for users to get a
  9. //  simple response from the keyboard. The STRING argument is printed
  10. //  on the standard output (usually the screen), and the program waits
  11. //  until input is entered. Input then returns the input, which can be
  12. //  either a string, or a number. If you want to force the input to be
  13. //  a string, then use the second, and optional argument, "s" to force
  14. //  the return value to be a string.
  15.  
  16. //  If the user does not enter anything when prompted, then input
  17. //  returns an empty matrix.
  18.  
  19. //-------------------------------------------------------------------//
  20.  
  21. input = function ( STRING, S )
  22. {
  23.   fprintf ("stdout", "%s", STRING);
  24.   ans = getline ("stdin");
  25.  
  26.   if (length (ans) == 0)
  27.   {
  28.     return [];
  29.   else
  30.     if (exist (S))
  31.     {
  32.       if (class (ans.[1]) == "num")
  33.       {
  34.         return num2str (ans.[1])
  35.       else
  36.         return ans.[1];
  37.       }
  38.     else
  39.       return ans.[1]
  40.     }
  41.   }
  42. };
  43.