Ohh... that MAX_SIZE thing makes things a lot clearer now... actually, it's still kinda confusing but... *shrug*
Okay, errors first... these are really friggin' subtle errors...
Code:
if (i<MAX_SIZE && (str[i] = getchar() != '\n')) {
if (!is_full())
push (str[i]);
i++;
}
I actually wrote my own stack and compiled your code, and the first time I ran it, it actually gave me a happy face as its answer. Apparantly this is because
str[i] = getchar() != '\n'
is evaluated as...
str[i] = (getchar() != '\n')
Remember that assignment operators are evaluated after boolean operators? So, you'll have to change your code to explicitly evaluate the assignment first...
Code:
if (i<MAX_SIZE && ((str[i] = getchar()) != '\n')) {
if (!is_full())
push (str[i]);
i++;
}
When I ran this code, I only got the first letter of what I typed in. Looking at it again, I noticed that you're using an if statement here... Aha, so this stuff is only being evaluated once! Replacing the if with a while so it would loop untill the end of input...
Code:
while (i<MAX_SIZE && ((str[i] = getchar()) != '\n')) {
if (!is_full())
push (str[i]);
i++;
}
And it worked perfectly. Try makin' those changes, and see if your code works.
Now, not wanting to be unneccisarily critical, I do think it's important that the statement is also clarafied a bit. Basically, the i < MAX_SIZE really shouldn't be there. I mean really, that bit of code is checking to see if it's overflowing the stack... but it's better to use your stack function is_full() to check for that, so...
Code:
while ((!is_full()) && ((str[i] = getchar()) != '\n')) {
if (!is_full())
push (str[i]);
i++;
}
Also, putting that check there makes the check inside the body not really all that usefull anymore... so we can scrap that too...
Code:
while ((!is_full()) && ((str[i] = getchar()) != '\n')) {
push (str[i]);
i++;
}
Finally, what is str[i] actually doing? If your code needs to keep a record of the input in an array, then your code is an effective way to do it while going through the stack, but if you're just pushing the values to a stack, ou can just use one temporary value...
Code:
while (!is_full() && (i = getchar()) != '\n') {
push (i);
}
Notice that I just kinda abandoned the use of i as a count variable, I'm just using it as a temporary variable to hold a char now.
I hope that makes the code more understandable. This part of the main function is really the only part that had problems. Feel free to ask if anything isn't understandable.