diff --git a/chapter_4/exercise_4_06/variables.c b/chapter_4/exercise_4_06/variables.c index de8af9d..d706ce6 100644 --- a/chapter_4/exercise_4_06/variables.c +++ b/chapter_4/exercise_4_06/variables.c @@ -121,7 +121,15 @@ int main(void) break; case VARGET: - push(var_buff[var - 'a']); + // Check if the variable has been assigned previously + if (var - 'a' <= (varindex - 1)) + { + push(var_buff[var - 'a']); + } + else + { + printf("Error: undefined variable.\n"); + } break; case '\n':