jac@yoko.rutgers.edu (Jonathan A. Chandross) (12/02/90)
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