Article View: comp.sources.apple2
Article #24v001SRC021: stoi -- String To Integer Library Function
From: Jonathan A. Chandross
Date: Sat, 01 Dec 1990 22:06
Date: Sat, 01 Dec 1990 22:06
54 lines
1351 bytes
1351 bytes
Submitted-by: NONE
Posting-number: Volume 1, Source:21
Archive-name: library/c/stoi
Architecture: ANY_2
Version-number: 1.00
This is a C library function to convert a string (char *) into an
integer (int).
Enjoy.
=stoi.c
-/*
- * stoi.c
- *
- * Library function to convert string to integer (checks sign).
- *
- * Input:
- * string of digits: [+|-] digit+
- * Output:
- * integer representing string of digits.
- *
- * Contributed Anonymously. Written: November 1983
- *
- * Version 1.00
- *
- */
-
-#define BLANK ' '
-#define TAB '\t'
-#define NL '\n'
-
-stoi(s)
-char *s ;
-{
- int n, sign ;
-
- while( *s == BLANK || *s == NL || *s == TAB )
- s++ ;
-
- sign = 1 ;
- if( *s == '+' )
- s++ ;
- else if( *s == '-' ) {
- sign = -1 ;
- s++ ;
- }
- for( n=0 ; *s >= '0' && *s <= '9' ; s++ )
- n = 10 * n + *s - '0' ;
- return( sign * n ) ;
-}
-
+ END OF ARCHIVE
Technical Details
Message-ID:
<Dec.1.17.06.40.1990.25091@yoko.rutgers.edu>Path:
arc1-ca.pugleaf.net!wuarchive!uwm.edu!rutgers!aramis.rutgers.edu!paul.rutgers.edu!yoko.rutgers.edu!jacShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!wuarchive!uwm.edu!rutgers!aramis.rutgers.edu!paul.rutgers.edu!yoko.rutgers.edu!jac From: jac@yoko.rutgers.edu (Jonathan A. Chandross) Newsgroups: comp.sources.apple2 Subject: v001SRC021: stoi -- String To Integer Library Function Message-ID: <Dec.1.17.06.40.1990.25091@yoko.rutgers.edu> Date: 1 Dec 90 22:06:41 GMT Organization: Rutgers Univ., New Brunswick, N.J. Lines: 54 Approved: jac@paul.rutgers.edu