]> diplodocus.org Git - nmh/blob - sbr/m_atoi.c
new.c: Order two return statements to match comment.
[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
12
13 int
14 m_atoi (char *str)
15 {
16 int i;
17 char *cp;
18
19 for (i = 0, cp = str; *cp; cp++) {
20 if (!isdigit((unsigned char) *cp))
21 return 0;
22
23 i *= 10;
24 i += (*cp - '0');
25 }
26
27 return i;
28 }