#scanf_s goes crazy with char inputs

1 messages · Page 1 of 1 (latest)

junior estuary
#

with integer inputs it works well

#

but with inputs that are not integers it goes crazy

#

i tried adding a getchar() but there is another problem , if i type a word with more charatters it prints the error message as much times as the charatters in the word

#

nevermind

#
#include<stdio.h>

void homepage(void);
int main() 
{
    printf("hello sir, what would you like to order?\n");
    homepage();
    getchar();
    return 0;
    
}
void homepage(void)
{
    int chapter;

    printf("homepage\n");
    printf("1-\tfirst plates\n2-\tsecond plates\n3-\tappetizer\n");
    scanf_s("%d", &chapter);
    while(chapter <1 || chapter > 3 || chapter == NULL)
    {
        if(-858993460 != chapter){ printf("\ninvalid input\n"); }
        scanf_s("%d", &chapter);
        getchar();
    }
    printf("you choosed: %d", chapter);
}```