summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/FC/NTOI.C
diff options
context:
space:
mode:
authorGravatar Mark Zbikowski2024-04-25 21:24:10 +0100
committerGravatar Microsoft Open Source2024-04-25 22:32:27 +0000
commit2d04cacc5322951f187bb17e017c12920ac8ebe2 (patch)
tree80ee017efa878dfd5344b44249e6a241f2a7f6e2 /v4.0/src/CMD/FC/NTOI.C
parentMerge pull request #430 from jpbaltazar/typoptbr (diff)
downloadms-dos-main.tar.gz
ms-dos-main.tar.xz
ms-dos-main.zip
MZ is back!HEADmain
Diffstat (limited to 'v4.0/src/CMD/FC/NTOI.C')
-rw-r--r--v4.0/src/CMD/FC/NTOI.C37
1 files changed, 37 insertions, 0 deletions
diff --git a/v4.0/src/CMD/FC/NTOI.C b/v4.0/src/CMD/FC/NTOI.C
new file mode 100644
index 0000000..267fce7
--- /dev/null
+++ b/v4.0/src/CMD/FC/NTOI.C
@@ -0,0 +1,37 @@
1/* convert an arbitrary based number to an integer */
2
3#include <ctype.h>
4#include "tools.h"
5
6/* p points to characters, return -1 if no good characters found
7 * and base is 2 <= base <= 16
8 */
9int ntoi (p, base)
10char *p;
11int base;
12{
13 register int i, c;
14 flagType fFound;
15
16 if (base < 2 || base > 16)
17 return -1;
18 i = 0;
19 fFound = FALSE;
20 while (c = *p++) {
21 c = tolower (c);
22 if (!isxdigit (c))
23 break;
24 if (c <= '9')
25 c -= '0';
26 else
27 c -= 'a'-10;
28 if (c >= base)
29 break;
30 i = i * base + c;
31 fFound = TRUE;
32 }
33 if (fFound)
34 return i;
35 else
36 return -1;
37}