Hi,

so creating a menu with the choices of 1-5 (integers) and saving the result into "scanfResult" worked very nicely so Ive tried to implement the same logic to characters but somehow it doesnt work. The code doesnt printout any errors but if you type in a number it will just quit the programm instead of staying in the loop.

ChatGPT this time also couldnt help me (used it this week and I have to say its an amazing tool if you have questions, but doesnt work always)

SO does this even work with characters or is something wrong with the code ?

I was under the impression that you can save the result of scanf whether you use %d / %c / %s or whatever and it will return/save the value 0 (didnt work) or 1 (worked) into like in this example "scanfResult". So if you use for example "%d" in "scanf" and someone enters in a character it will save the result as "0" or am I thinking wrong and it only works with integers ?

Hope you understand what Iam trying to ask ...

Code:
#include <stdio.h>
#include <stdbool.h>

int main(void)
{
    char choice;
    int scanfResult = 0;

    while(true)
    {
        printf("Do you agree ? (y/n): ");
        scanfResult = scanf(" %c", &choice);

        if(scanfResult == 1)
        {
            if(choice == 'y' || choice == 'Y')
                printf("I agree\n");
            else if(choice == 'n' || choice == 'N')
                printf("I disagree\n");
            break; // Exit the loop if a valid character is entered
        }
        
        else if(scanfResult == 0)
        {
            while (getchar() != '\n'); // Clear the input buffer
            printf("Invalid input. Please enter 'y' or 'n'.\n");
            continue; // Continue the loop to ask again
        }
    }
    return 0;
}