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[])
143
143
if (c == '-' )
144
144
{
145
145
int next = getch ();
146
- if (! isdigit ( next ) && next != '. ' )
146
+ if (next == '\n' || next == ' ' || next == '\t ' )
147
147
{
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 ;
149
158
}
150
-
151
- s [i ] = c ;
152
- ungetch (c = next );
153
159
}
154
160
else
155
161
{
Original file line number Diff line number Diff line change @@ -201,13 +201,19 @@ int getop(char s[])
201
201
if (c == '-' )
202
202
{
203
203
int next = getch ();
204
- if (! isdigit ( next ) && next != '. ' )
204
+ if (next == '\n' || next == ' ' || next == '\t ' )
205
205
{
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 ;
207
216
}
208
-
209
- s [i ] = c ;
210
- ungetch (c = next );
211
217
}
212
218
else
213
219
{
Original file line number Diff line number Diff line change @@ -215,13 +215,19 @@ int getop(char s[])
215
215
if (c == '-' )
216
216
{
217
217
int next = getch ();
218
- if (! isdigit ( next ) && next != '. ' )
218
+ if (next == '\n' || next == ' ' || next == '\t ' )
219
219
{
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 ;
221
230
}
222
-
223
- s [i ] = c ;
224
- ungetch (c = next );
225
231
}
226
232
else
227
233
{
Original file line number Diff line number Diff line change @@ -258,13 +258,19 @@ int getop(char s[])
258
258
if (c == '-' )
259
259
{
260
260
int next = getch ();
261
- if (! isdigit ( next ) && next != '. ' )
261
+ if (next == '\n' || next == ' ' || next == '\t ' )
262
262
{
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 ;
264
273
}
265
-
266
- s [i ] = c ;
267
- ungetch (c = next );
268
274
}
269
275
else
270
276
{
Original file line number Diff line number Diff line change @@ -267,14 +267,19 @@ int getop(char s[])
267
267
if (c == '-' )
268
268
{
269
269
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
271
276
{
272
277
return next ;
273
278
}
274
-
275
- s [ i ] = c ;
276
- c = next ;
277
- -- line_i ;
279
+ else
280
+ {
281
+ s [ ++ i ] = c = next ;
282
+ }
278
283
}
279
284
else
280
285
{
You can’t perform that action at this time.
0 commit comments