printf("%c.\n", (getText(precrmo_menu[3]))[0]);
char input[3];
input[0] = (getText(precrmo_menu[3]))[0];
printf("we lived");
if (strcmp(input, "") != 0 && !isblank(input) && isdigit(input))
{
clearMenu(precrmo_menu, precrmo_menu_length);
menu = 2;
}
This code prints out the first character (followed by a period and a line break) but then skips the printf("we lived");
command and hits the if
statement and segfaults. When I change the condition to just
if (strcmp(input, ""))
then it again skips the printf("we lived");
, hits the condition, finds it true, clears the menu, and then stalls out. If I close the window, the terminal THEN prints out "we lived"
.
I suppose it's helpful to indicate that this code is within an intentional infinite loop that checks for MOUSE_EVENT and KEY_EVENT. If a click is within a certain zone, it will change menus by making pieces visible/not-visible and changing an int menu
that holds a different numerical value based on which menu I'm on. Also, clearMenu()
is used elsewhere with no glitches (all it does is loop through the menu array and calling isVisible
on them to turn them not-visible).
Furthermore, it's interesting to note that within the loop, I've got an if-else ladder to check which menu number I'm on, including an escape mechanism:
else if(getEventType(event) == KEY_PRESSED)
{
menu = -1;
}
THIS code also still executes after the program seems to stall out, and if I do press a key and get out, it also waits until the window is closed to print out "we lived"
I don't understand how that command could be held in reserve but the other printf didn't... Anyone know what's going on?
if (strcmp(input, "") != 0 && !isblank(input) && isdigit(input))
are you checking whether the first char ininput
isn't null? Can't you logically simplify that toif(isdigit(input[0])
? (I'm not sure how that line even compiles, given that you are passing a string toisblank()
andisdigit()
when both of those take an int (or a char).isalpha
and the alike everything compiles perfectly without even a warning since pointers can't be implicitly casted to ints until I found the answer.