]> diplodocus.org Git - nmh/blob - sbr/m_atoi.c
Improve fmttest output
[nmh] / sbr / m_atoi.c
1 /* m_atoi.c -- Parse a string representation of a message number, and
2 * -- return the numeric value of the message. If the string
3 * -- contains any non-digit characters, then return 0.
4 *
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
8 */
9
10 #include "h/mh.h"
11 #include "m_atoi.h"
12
13
14 int
15 m_atoi (char *str)
16 {
17 int i;
18 char *cp;
19
20 for (i = 0, cp = str; *cp; cp++) {
21 if (!isdigit((unsigned char) *cp))
22 return 0;
23
24 i *= 10;
25 i += (*cp - '0');
26 }
27
28 return i;
29 }