home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / libs / plotlib.lha / Plot_1.lzh / Demo / GetNumber.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-18  |  4.3 KB  |  134 lines

  1. /****************************************************************
  2. *                                                                                                                              *
  3. * Filename : GetNumber.c                                                                                *
  4. *                                                                                                                              *
  5. *****************************************************************
  6. *                                                                                                                              *
  7. *    Comment : Dieses File beinhaltet all Routinen um Zahlen              *
  8. *                        Intuitionlike einzulesen.                                                     *
  9. *                                                                                                                              *
  10. *                                                                                                                              *
  11. *            Rev : V1.0                                                                                              *
  12. *                                                                                                                              *
  13. *    History : V1.0 erstellen dieses Files                              01.06.89    *
  14. *                                                                                                                              *
  15. *         Bugs : keine bekannten                                                                          *
  16. *                                                                                                                              *
  17. *        Autor : Oesch Silvano                                                                              *
  18. *                                                                                                                              *
  19. *        Datum : 01.06.89                                                                                      *
  20. *                                                                                                                              *
  21. ****************************************************************/
  22.  
  23. /****************************************************************
  24. *                                                                                                                                *
  25. * allgemeine Includedateien                                                                            *
  26. *                                                                                                                                *
  27. ****************************************************************/
  28.  
  29. #include <exec/types.h>
  30. #include <exec/exec.h>
  31. #include <intuition/intuition.h>
  32. #include <intuition/screens.h>
  33. #include <intuition/intuitionbase.h>
  34. #include <devices/printer.h>
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <ctype.h>
  39. #include <math.h>
  40. #include <errno.h>
  41.  
  42. /****************************************************************
  43. *                                                                                                                                *
  44. *    Funktion : ValidFloat()                                                                                *
  45. *                                                                                                                                *
  46. *****************************************************************
  47. *                                                                                                                                *
  48. *        Input : str                                                                                                    *
  49. *                                                                                                                                *
  50. *     Output : int                                                                                                    *
  51. *                                                                                                                                *
  52. *****************************************************************
  53. *                                                                                                                                *
  54. *    Comment :                                                                                                            *
  55. *                                                                                                                                *
  56. *                                                                                                                                *
  57. *                                                                                                                                *
  58. *            Rev : V1.0                                                                                                *
  59. *                                                                                                                                *
  60. *    History : V1.0 erstellen dieses Files                                08.08.89    *
  61. *                                                                                                                                *
  62. *         Bugs : keine bekannten                                                                            *
  63. *                                                                                                                                *
  64. *        Autor : Oesch Silvano                                                                                *
  65. *                                                                                                                                *
  66. *        Datum : 08.08.89                                                                                        *
  67. *                                                                                                                                *
  68. ****************************************************************/
  69.  
  70. static int ValidFloat(str)
  71. char *str;                                                    /* Inputstring                            */
  72. {
  73.     int i= NULL;                                            /* Charakter Position                */
  74.     char valid[]="0123456789.+-eE";        /* gültige Charakter                */
  75.  
  76.     do
  77.     {
  78.         if (strchr(valid,str[i++]) == NULL)
  79.             return(i);                                        /* Gib inval. Zeichenpos        */
  80.     }
  81.     while (str[i]);                                        /* solange Zeichen da sind    */
  82.     return (-1);                                            /* alles ok                                    */
  83. }
  84.  
  85. /****************************************************************
  86. *                                                                                                                                *
  87. *    Funktion : GetNumber()                                                                                *
  88. *                                                                                                                                *
  89. *****************************************************************
  90. *                                                                                                                                *
  91. *        Input : zahl,string,text,typ                                                                *
  92. *                                                                                                                                *
  93. *     Output : BOOLEAN                                                                                            *
  94. *                                                                                                                                *
  95. *****************************************************************
  96. *                                                                                                                                *
  97. *            Rev : V1.0                                                                                                *
  98. *                                                                                                                                *
  99. *    History : V1.0 erstellen dieses Files                                                    *
  100. *                                                                                                                                *
  101. *         Bugs : keine bekannten                                                                            *
  102. *                                                                                                                                *
  103. *        Autor : Oesch Silvano                                                                                *
  104. *                                                                                                                                *
  105. *        Datum : 08.08.89                                                                                        *
  106. *                                                                                                                                *
  107. ****************************************************************/
  108.  
  109. int GetFloat(title,value)
  110. char title[];
  111. double *value;
  112. {
  113.  
  114.     int    erfolg,novalidchar;
  115.  
  116.     char buffer[20];
  117.  
  118.     buffer[0] = 0x00;
  119.     erfolg = GetString(buffer,title,NULL,strlen(title)+10,19);
  120.     if (erfolg)
  121.     {
  122.         novalidchar = ValidFloat(buffer);
  123.         if (novalidchar == -1)
  124.             *value = atof(buffer);
  125.         else
  126.         {
  127.             DisplayBeep(NULL);
  128.             erfolg = FALSE;
  129.         }
  130.     }
  131.     return(erfolg);
  132. }
  133.  
  134.