/programs/develop/ktcc/trunk/libc/stdlib/atoi.c |
0,0 → 1,21 |
#include "stdio.h" |
#include "stdlib.h" |
#include "ctype.h" |
|
|
/* |
** atoi(s) - convert s to integer. |
*/ |
int atoi(char *s) |
{ |
int sign, n; |
while(isspace(*s)) ++s; |
sign = 1; |
switch(*s) { |
case '-': sign = -1; |
case '+': ++s; |
} |
n = 0; |
while(isdigit(*s)) n = 10 * n + *s++ - '0'; |
return (sign * n); |
} |
/programs/develop/ktcc/trunk/libc/stdlib/atoib.cpp |
0,0 → 1,22 |
#include "stdio.h" |
#include "stdlib.h" |
#include "ctype.h" |
|
/* |
** atoib(s,b) - Convert s to "unsigned" integer in base b. |
** NOTE: This is a non-standard function. |
*/ |
int atoib(char *s,int b) |
{ |
int n, digit; |
n = 0; |
while(isspace(*s)) ++s; |
while((digit = (127 & *s++)) >= '0') { |
if(digit >= 'a') digit -= 87; |
else if(digit >= 'A') digit -= 55; |
else digit -= '0'; |
if(digit >= b) break; |
n = b * n + digit; |
} |
return (n); |
} |
/programs/develop/ktcc/trunk/libc/stdlib/itoa.c |
0,0 → 1,21 |
#include "stdio.h" |
#include "stdlib.h" |
#include "ctype.h" |
|
/* |
** itoa(n,s) - Convert n to characters in s |
*/ |
void itoa(int n,char* s) |
{ |
int sign; |
char *ptr; |
ptr = s; |
if ((sign = n) < 0) n = -n; |
do { |
*ptr++ = n % 10 + '0'; |
} while ((n = n / 10) > 0); |
if (sign < 0) *ptr++ = '-'; |
*ptr = '\0'; |
reverse(s); |
} |
|
/programs/develop/ktcc/trunk/libc/stdlib/itoab.c |
0,0 → 1,24 |
#include "stdio.h" |
#include "stdlib.h" |
#include "ctype.h" |
|
/* |
** itoab(n,s,b) - Convert "unsigned" n to characters in s using base b. |
** NOTE: This is a non-standard function. |
*/ |
void itoab(int n,char* s,int b) |
{ |
char *ptr; |
int lowbit; |
ptr = s; |
b >>= 1; |
do { |
lowbit = n & 1; |
n = (n >> 1) & 32767; |
*ptr = ((n % b) << 1) + lowbit; |
if(*ptr < 10) *ptr += '0'; else *ptr += 55; |
++ptr; |
} while(n /= b); |
*ptr = 0; |
reverse (s); |
} |