I tested a simple program in C to validate user data. It is assumed that the program determines whether the character entered by the user is a number, alphabet, or special character.
Somehow, the code identifies each type of input character as a number. I added the code below, I would appreciate if someone could kindly indicate where I am mistaken?
// Program user input and determine if it is a character, number, or special character
#include<stdio.h>
#include<conio.h>
#include<string.h>
char ch;
int main()
{
clrscr();
printf("Enter a character \n");
scanf("%c \n",ch);
if ((ch>='A'&& ch<='Z')||(ch>='a'&& ch<='z') )
{
printf("The character entered is an alphabet \n" );
}
else if ((ch>=0)&&(ch<=9))
{
printf("Character entered is an number \n");
}
else
{
printf("Character entered is a special character");
}
return 0;
}
source
share