home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / apple2 / 43 < prev    next >
Encoding:
Internet Message Format  |  1990-12-02  |  1.3 KB

  1. Path: wuarchive!uwm.edu!rutgers!aramis.rutgers.edu!paul.rutgers.edu!yoko.rutgers.edu!jac
  2. From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
  3. Newsgroups: comp.sources.apple2
  4. Subject: v001SRC021:  stoi -- String To Integer Library Function
  5. Message-ID: <Dec.1.17.06.40.1990.25091@yoko.rutgers.edu>
  6. Date: 1 Dec 90 22:06:41 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 54
  9. Approved: jac@paul.rutgers.edu
  10.  
  11.  
  12. Submitted-by: NONE
  13. Posting-number: Volume 1, Source:21
  14. Archive-name: library/c/stoi
  15. Architecture: ANY_2
  16. Version-number: 1.00
  17.  
  18. This is a C library function to convert a string (char *) into an
  19. integer (int).
  20.  
  21. Enjoy.
  22.  
  23. =stoi.c
  24. -/*
  25. - * stoi.c
  26. - *
  27. - * Library function to convert string to integer (checks sign).
  28. - *
  29. - * Input: 
  30. - *    string of digits:    [+|-] digit+
  31. - * Output:
  32. - *    integer representing string of digits.
  33. - *
  34. - * Contributed Anonymously.  Written: November 1983
  35. - *
  36. - * Version 1.00
  37. - *
  38. - */
  39. -
  40. -#define BLANK ' '
  41. -#define TAB   '\t'
  42. -#define NL    '\n'
  43. -
  44. -stoi(s)
  45. -char *s ;
  46. -{
  47. -    int n, sign ;
  48. -
  49. -    while( *s == BLANK || *s == NL || *s == TAB )
  50. -        s++ ;
  51. -
  52. -    sign = 1 ;
  53. -    if( *s == '+' )
  54. -        s++ ;
  55. -    else if( *s == '-' ) {
  56. -        sign = -1 ;
  57. -        s++ ;
  58. -    }
  59. -    for( n=0 ; *s >= '0' && *s <= '9' ; s++ )
  60. -        n = 10 * n + *s - '0' ;
  61. -    return( sign * n ) ;
  62. -}
  63. -
  64. + END OF ARCHIVE
  65.