blob: 8870895cd0d9ce75ff775e736f77f20c58fddcb8 (
plain)
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
|
#include <stdio.h>
#include <ctype.h>
#define NUMBER '0'
int getch(void);
void ungetch(int);
/* get next operator or numeric operand */
int
getop(char s[])
{
int i, c;
while((s[0] = c = getch()) == ' ' || c == '\t');
s[1] = '\0';
/* not a number */
if (!isdigit(c) && c != '.') {
return c;
}
i = 0;
/* collect integer part */
if (isdigit(c)) {
while (isdigit(s[++i] = c = getch()));
}
/* collect fraction part */
if (c == '.') {
while (isdigit(s[++i] = c = getch()));
}
s[i] = '\0';
if (c != EOF) {
ungetch(c);
}
return NUMBER;
}
|