-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan_ulong.c
72 lines (67 loc) · 1.1 KB
/
scan_ulong.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* $Log: scan_ulong.c,v $
* Revision 1.1 2014-08-18 10:20:25+05:30 Cprogrammer
* Initial revision
*
*
*/
#include "scan.h"
#ifndef lint
static char sccsid[] = "$Id: scan_ulong.c,v 1.1 2014-08-18 10:20:25+05:30 Cprogrammer Exp mbhangui $";
#endif
unsigned int
scan_ulong(s, u)
register char *s;
register unsigned long *u;
{
register unsigned int pos;
register unsigned long result;
register unsigned long c;
pos = 0;
result = 0;
while ((c = (unsigned long) (unsigned char) (s[pos] - '0')) < 10)
{
result = result * 10 + c;
++pos;
}
*u = result;
return pos;
}
unsigned int
scan_int(s, i)
register char *s;
register int *i;
{
register unsigned int pos;
register int result;
register unsigned char c;
int sign;
pos = 0;
result = 0;
sign = 1;
/*-
* determine sign of the number
*/
switch (s[0])
{
case '\0':
return 0;
case '-':
++pos;
sign = -1;
break;
case '+':
++pos;
sign = 1;
break;
default:
break;
}
while ((c = (unsigned char)(s[pos] - '0')) < 10)
{
result = result * 10 + c;
++pos;
}
*i = result * sign;
return pos;
}