aboutsummaryrefslogtreecommitdiff
path: root/7.5/op.c
blob: 426baadc08b7e400983058cc047e16fbdc24113c (plain) (blame)
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
#include <stdio.h>
#include <ctype.h>
#include "op.h"

char getop(char *op, size_t len)
{
	int rs;
	double f;

	while ((rs = scanf("%c", op)) != EOF)
		if (*op != ' ' && *op != '\t')
			break;

	op[1] = '\0';
	if (rs == EOF)
		return EOF;

	if (!isdigit(*op) && *op != '.')
		return *op;

	ungetc(*op, stdin);
	scanf("%lf", &f);
	snprintf(op, len, "%lf", f);
	return NUM;
}