solution.c (563B)
1 int atoi(s) /* convert s to integer */ 2 char s[]; 3 { 4 int i, n; 5 6 n = 0; 7 for (i = 0; s[i] >= '0' && s[i] <= '9'; ++i) 8 n = 10 * n + s[i] - '0'; 9 return(n); 10 } 11 12 int htoi(s) 13 char s[]; 14 { 15 int n; 16 char *p; 17 18 n = 0; 19 for (p = s; 20 (*p >= '0' && *p <= '9') 21 || (*p >= 'a' && *p <= 'f') 22 || (*p >= 'A' && *p <= 'F'); 23 ++p) { 24 n *= 16; 25 if (*p >= '0' && *p <= '9') { 26 n += *p - '0'; 27 } else if (*p >= 'a' && *p <= 'f') { 28 n += *p - 'a' + 10; 29 } else { 30 n += *p - 'A' + 10; 31 } 32 } 33 return(n); 34 }