File tree Expand file tree Collapse file tree 5 files changed +54
-25
lines changed
Expand file tree Collapse file tree 5 files changed +54
-25
lines changed Original file line number Diff line number Diff line change @@ -143,13 +143,19 @@ int getop(char s[])
143143 if (c == '-' )
144144 {
145145 int next = getch ();
146- if (! isdigit ( next ) && next != '. ' )
146+ if (next == '\n' || next == ' ' || next == '\t ' )
147147 {
148- return next ;
148+ ungetch (next );
149+ return c ; // return '-' as operator
150+ }
151+ else if (!isdigit (next ) && next != '.' )
152+ {
153+ return next ; // not a number
154+ }
155+ else // number like "-5", "-.6" etc, next is digit or '.'
156+ {
157+ s [++ i ] = c = next ;
149158 }
150-
151- s [i ] = c ;
152- ungetch (c = next );
153159 }
154160 else
155161 {
Original file line number Diff line number Diff line change @@ -201,13 +201,19 @@ int getop(char s[])
201201 if (c == '-' )
202202 {
203203 int next = getch ();
204- if (! isdigit ( next ) && next != '. ' )
204+ if (next == '\n' || next == ' ' || next == '\t ' )
205205 {
206- return next ;
206+ ungetch (next );
207+ return c ; // return '-' as operator
208+ }
209+ else if (!isdigit (next ) && next != '.' )
210+ {
211+ return next ; // not a number
212+ }
213+ else // number like "-5", "-.6" etc, next is digit or '.'
214+ {
215+ s [++ i ] = c = next ;
207216 }
208-
209- s [i ] = c ;
210- ungetch (c = next );
211217 }
212218 else
213219 {
Original file line number Diff line number Diff line change @@ -215,13 +215,19 @@ int getop(char s[])
215215 if (c == '-' )
216216 {
217217 int next = getch ();
218- if (! isdigit ( next ) && next != '. ' )
218+ if (next == '\n' || next == ' ' || next == '\t ' )
219219 {
220- return next ;
220+ ungetch (next );
221+ return c ; // return '-' as operator
222+ }
223+ else if (!isdigit (next ) && next != '.' )
224+ {
225+ return next ; // not a number
226+ }
227+ else // number like "-5", "-.6" etc, next is digit or '.'
228+ {
229+ s [++ i ] = c = next ;
221230 }
222-
223- s [i ] = c ;
224- ungetch (c = next );
225231 }
226232 else
227233 {
Original file line number Diff line number Diff line change @@ -258,13 +258,19 @@ int getop(char s[])
258258 if (c == '-' )
259259 {
260260 int next = getch ();
261- if (! isdigit ( next ) && next != '. ' )
261+ if (next == '\n' || next == ' ' || next == '\t ' )
262262 {
263- return next ;
263+ ungetch (next );
264+ return c ; // return '-' as operator
265+ }
266+ else if (!isdigit (next ) && next != '.' )
267+ {
268+ return next ; // not a number
269+ }
270+ else // number like "-5", "-.6" etc, next is digit or '.'
271+ {
272+ s [++ i ] = c = next ;
264273 }
265-
266- s [i ] = c ;
267- ungetch (c = next );
268274 }
269275 else
270276 {
Original file line number Diff line number Diff line change @@ -267,14 +267,19 @@ int getop(char s[])
267267 if (c == '-' )
268268 {
269269 int next = line [line_i ++ ];
270- if (!isdigit (next ) && next != '.' )
270+ if (next == '\n' || next == ' ' || next == '\t' || next == '\0' )
271+ {
272+ -- line_i ;
273+ return '-' ;
274+ }
275+ else if (!isdigit (next ) && next != '.' ) // not a number
271276 {
272277 return next ;
273278 }
274-
275- s [ i ] = c ;
276- c = next ;
277- -- line_i ;
279+ else
280+ {
281+ s [ ++ i ] = c = next ;
282+ }
278283 }
279284 else
280285 {
You can’t perform that action at this time.
0 commit comments