From 92701707e22651a74442b43387f07abf565844cd Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Tue, 21 Dec 2021 18:19:50 +0800 Subject: 4.11 --- 4/11.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to '4') diff --git a/4/11.c b/4/11.c index e33ac52..e6c0645 100644 --- a/4/11.c +++ b/4/11.c @@ -126,11 +126,9 @@ int getch() { return (bufp > 0) ? buf[--bufp] : getchar(); } int getop(char s[]) { int c, i, rc; - static int pc; + static int pc = EOF; - pc = EOF; - - if (pc != EOF) { + if (pc != EOF && pc != ' ' && pc != '\t') { c = pc; pc = EOF; } else { @@ -140,17 +138,16 @@ int getop(char s[]) { } // special characters and operators - if (c == 0 || c == '+' || c == '*' || c == '/' || c == '%' || c == '\n' || - (c == '-' && !isdigit(c)) || c == EOF) + if (c == '+' || c == '*' || c == '/' || c == '%' || c == '\n' || c == EOF) return c; i = 0; - if (isdigit(c) || c == '-' || c == '.') { + if (isdigit(c) || c == '.' || c == '-') { while (isdigit((s[++i] = c = getch())) || c == '.') ; pc = c; - rc = NUM; + rc = i == 1 && s[0] == '-' ? '-' : NUM; } else if (isalpha(c) && getch() == '=') { s[++i] = c; rc = '='; -- cgit v1.2.3