I wrote this code:
Code:
#include "includes.h"
int main(void) {
int number;
char char1;
printf("%s", "Enter a number: ");
if (scanf(" %d", &number) != 1)
{
printf("%s\n", "You didnt enter a number!");
return -1;
}
else
{
printf("%s", "Enter a character: ");
if (scanf(" %c", &char1) != 1)
{
printf("%s\n", "You didnt enter a character!");
return -1;
}
else
{
printf("%s%d%s%c\n", "The number you entered is ", number, " and the character is ", char1);
}
}
return 0;
}
I wanna check if the character i enter is a character or no , i mean char1 variable , the check for the number is fine , but the scanf in the character input always returns 1 whether i enter a single character or various ones.
Thanks for help.