Skip to content

Commit 546de27

Browse files
authored
fix variables.c
Changed the command letters to capital-case to prevent overlapping with VARGET
1 parent 933e245 commit 546de27

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

chapter_4/exercise_4_06/variables.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,23 @@ int main(void)
9595
push(sin(pop()));
9696
break;
9797

98-
case 'e':
98+
case 'E':
9999
push(exp(pop()));
100100
break;
101101

102-
case 'h':
102+
case 'H':
103103
view_head();
104104
break;
105105

106-
case 'd':
106+
case 'D':
107107
duplicate();
108108
break;
109109

110-
case 's':
110+
case 'S':
111111
swap();
112112
break;
113113

114-
case 'c':
114+
case 'C':
115115
clear();
116116
break;
117117

@@ -244,7 +244,7 @@ int getop(char s[])
244244

245245
s[1] = '\0';
246246

247-
if (isalpha(c))
247+
if (isalpha(c) && !(c >= 'A' && c <= 'Z'))
248248
{
249249
var = c;
250250
return VARGET;
@@ -296,3 +296,7 @@ int getop(char s[])
296296

297297
return NUMBER;
298298
}
299+
/* To prevent the variable checking in getop() from overlapping with the letter commands,
300+
make sure you set the commands to capital letters and explicitly tell the getop() to only
301+
check for variable-getting if the character is not capital
302+
e.g insteat of "if (isalpha(c))" you add "if (isalpha(c) && !(c >= 'A' && c >= 'Z'))"*/

0 commit comments

Comments
 (0)