i wrote this program and i want display 0, if the character entered is not an alphabet (!@#$% 5 or any other non alphabet)
can i have a quick solution
#include
void main ()
{
char char1,char2;
printf("\tEnter first character :");
scanf("\t%c", &char1);
printf("\tEnter second character :");
scanf("\n\t%c", &char2);
while (char2 < char1)
{
printf("\t!!!User must enter second character before the first\n");
printf("\tPlease enter valid second character :");
scanf("\n\t%c", &char2);
}
printf("\n\tNumerical Values Between %c and %c\n",char1,char2);
printf("\t................................\n");
printf("\n\tChar\tDecimal\tOctal\tHex\n");
printf("\t=============================\n");
while (char1 <= char2)
{
printf("\t%c\t%d\t%o\t%x\n",char1,char1,char1,char1);
char1++;
}
getch();
}
I am not sure what exactly you want to do but, if I understand properly, you want to make sure that the char1 and char2 are always letters('a' to 'z' or 'A' to 'Z')?
If that is what you want then all you need is a while loop.
As you can see, it will keep repeating the while loop until the character is a letter. When it is a letter, it will go to the 'here:' which should be just after the while loop.
hey that not wot i need
bt thanx for ur kind reply
here is ma question...i have done this program n cannot run n also want to add one function
#include
#include
int main()
{
char input;
printf("Enter a character");
scanf("%s", &input);
if ( input >= 'A' && input<= 'Z' )
printf("The lower case equivalent is %s\n", static_cast ( input + 'a' - 'A' ) );
else if ( input>= 'a' && input <= 'z' )
printf("The upper case equivalent is %s\n", static_cast ( input + 'A' - 'a' ));
else
printf("The character is not a letter");
}
here the problem is num and special characters also accepting.. i want the program only accept alphabets and If the character entered is not an alphabet (!@#$% 5 or any other non alphabet), i want display 0
If the character entered is not an alphabet (!@#$% 5 or any other non alphabet), i want display 0
> I already posted a piece of code which evaluates wheter the character is an alphabet character or not ...can any one do that pllllz help meeeeee > Sure we can do that for you, but it's your homework ...you just need to add an if condition in the above program but u must need to know the ASCII range in which all those alphabets fall. > What do you think the following does? #if(('a'<=c && c<= 'z') || ('A'<=c && c<= 'Z'))