You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Removed the else-block of "if (c == '-')" and restructured the clear command so the "stack is empty" message is not displayed an extra time after the c command has already been called. E.g if on the first line you type 'c', the message is displayed. On the next line, the message is displayed again even if you only typed "9 9+" because the previous code structure in the clear function forced the sp variable to go down to -1.
Copy file name to clipboardExpand all lines: chapter_4/exercise_4_04/stack.c
+10-3Lines changed: 10 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -158,10 +158,16 @@ void swap(void)
158
158
159
159
voidclear(void)
160
160
{
161
-
do
161
+
/* do
162
162
{
163
163
stack[sp] = 0.0;
164
164
} while (sp--);
165
+
*/
166
+
// Replacing the above commented code with this one ensures messages of "stack empty" aren't displayed an extra time after c command is called in the program
167
+
while (sp>0)
168
+
{
169
+
stack[--sp] =0.0;
170
+
}
165
171
}
166
172
167
173
intbufp=0;
@@ -215,10 +221,11 @@ int getop(char s[])
215
221
s[++i] =c=next;
216
222
}
217
223
}
218
-
else
224
+
// Remove this else block so that a value like 1200 in the program won't be mistaken is 100. This block will skip the second digit that is read in the number parsing process
0 commit comments