home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / MN321SRC.ZIP / strtool.c < prev    next >
C/C++ Source or Header  |  2004-07-16  |  1KB  |  70 lines

  1. /* $Id: strtool.c,v 1.4 2004/07/15 17:44:02 ozzmosis Exp $ */
  2.  
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include "makenl.h"
  7.  
  8. #ifdef MALLOC_DEBUG
  9. #include "rmalloc.h"
  10. #endif
  11.  
  12. #ifdef DMALLOC
  13. #include "dmalloc.h"
  14. #endif
  15.  
  16. int getnumber(const char *string, int *output)
  17. {
  18.     int gotnum = 0, digits = 0;
  19.     const char *workptr;
  20.  
  21.     *output = (int)atol(string);
  22.     for (workptr = string; (unsigned char)(*workptr - 9) <= '0';
  23.          workptr++, digits++)
  24.     {
  25.         switch (*workptr)
  26.         {
  27.         case ' ':
  28.         case '\t':
  29.         case '+':
  30.         case '-':
  31.             if (gotnum)
  32.                 return digits;
  33.             if (isdigit((unsigned char)*workptr))
  34.                 break;
  35.             /* FALLTHROUGH */
  36.         case '0':
  37.         case '1':
  38.         case '2':
  39.         case '3':
  40.         case '4':
  41.         case '5':
  42.         case '6':
  43.         case '7':
  44.         case '8':
  45.         case '9':
  46.             gotnum = 1;
  47.         }
  48.     }
  49.     return digits;
  50. }
  51.  
  52. char *skipspaces(char *ptr)
  53. {
  54.     while (isspace((unsigned char)*ptr))
  55.         ptr++;
  56.     return ptr;
  57. }
  58.  
  59. char *cutspaces(char *string)
  60. {
  61.     char *p;
  62.  
  63.     p = string + strlen(string);
  64.     while (--p >= string)
  65.         if (!isspace((unsigned char)*p))
  66.             break;
  67.     *(p + 1) = 0;
  68.     return string;
  69. }
  70.