I'm having a very peculiar problem with my if / else if / else statement block. Certain inputs seems to be accessing multiple parts of the block, and some statements don't seem to be working at all. Here is my code:
Code:
int cc;
ii = 0;
for(cc = 0; cc < 1; cc--) { // infinite loop
fgets(aa[ii], LINE_SZ, stdin); // LINE_SZ = 90
if(strlen(aa[ii]) == 1) // WORKS
exit(0);
if(strlen(aa[ii]) > 80) {
fprintf(stderr, "Inside > 80\n");
} else if(aa[ii][0] == '<') {
fprintf(stderr, "Inside <");
// pop
if(ii == 0) {
fprintf(stderr, "Empty stack.\n");
} else {
printf("ii: %d", ii);
fprintf(stdout, aa[ii-1]);
}
} else if(aa[ii][0] == '>') {
fprintf(stderr, "Inside >\n");
// push
if(ii == stackSize) {
fprintf(stderr, "Full stack.\n");
} else {
strcpy(aa[ii], aa[ii]+1);
ii++;
}
} else {
// bad input
fprintf(stderr, "Inside else - Bad input.\n");
}
}
Even if my input line (aa[ii]) is over 80 chars long, it displays "Inside > 80" but then still goes to the else statement and displays "Inside else - Bad input."