Calls getch.c to get an operator or an operand,
put into the string s, which is supplied from the main program.
#include <stdio.h>
#include <ctype.h>
#include "getch.h"
#define NUMBER '\007'
int getop(char s[]) {
int i, c;
while ((s[0] = c = getch()) == ' ' || c == '\t');
s[1] = '\0';
if (!isdigit(c) && c != '.')
return c;
i = 0;
if (isdigit(c))
while (isdigit(s[++i] = c = getch()));
if (c == '.')
while (isdigit(s[++i] = c = getch()));
s[i] = '\0';
if (c != EOF)
ungetch(c);
return NUMBER;
}
Created: Nov 26, 1994
Last Revised: Dec 6, 1994
© Copyright 1994 Wei-Chang Shann
- Back to the main program.
- Back to the home page of
Wei-Chang Shann.
- Connect to the home page of
Department of Mathematics, National Central University,
Taiwan.
shann@math.ncu.edu.tw