#Help C

5 messages · Page 1 of 1 (latest)

eternal flame
#
int menu(void) {
    int menuOptLen = 3;
    int  menuOpt[] = {1, 2, 3};
    int k = -9999;

    while(elemNotInList(k, menuOpt, menuOptLen)) {
        system("clear");
    

    printf("=> " ANSI_COLOR_YELLOW  "MENU!"  ANSI_RESET_ALL "\n");
    printf("1.START\n");
    printf("2.LEAVE\n");
    printf("3.RESUME\n");;
    printf("=> " ANSI_COLOR_YELLOW  "\t\t\t Select an Option!"  ANSI_RESET_ALL "\n");    
        k = (int)(getc(stdin) - '0');
    }
return k;
}

can someone explain what is the function of k ? and exactly what is this row for? k = (int)(getc(stdin) - '0');

still meadowBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

hushed iron
#

it's a bit dirty it reads the input, gets the char and removes '0' to get the actual number out

#

as '0' != 0

still meadowBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.