I want to write a C program to test whether the character is uppercase, lowercase, digit or special symbol.

void main ()
{

char ch;

printf("\n Enter any character from the keyborad");

scanf("%c",&ch);

if (ch>=65&&ch<=90)

printf(" \n the character is uppercase);

if(ch>=91&&ch>=122)

printf(" \n the character is lowercase);

if(ch>=48&&ch<=57)
printf("\n You entered a digit );



}

My question how to print whether the character is a special symbol. I don't know this. Please can anyone point out.

Thanks

Since you are able to test for the first three, i think an else condition will be able to give you the fourth case, i.e a special character. Use your program to try this algorithm

if(element_is_a_lowercase)
print("lowercase")
else if(element_is_an_uppercase)
print("uppercase")
else if(element_is_a_digit)
print("digit")
else
print("is special")

hope it works!

Regards

Since you are able to test for the first three, i think an else condition will be able to give you the fourth case, i.e a special character. Use your program to try this algorithm

if(element_is_a_lowercase)
print("lowercase")
else if(element_is_an_uppercase)
print("uppercase")
else if(element_is_a_digit)
print("digit")
else
print("is special")

hope it works!

Regards

Thanks for this explanation. I would like to ask

1. Whether I can use ASCII code for to print special symbols, like I have done above in 3 cases. If so, would you please tell the codes.

2. Are there braces missing in my program after if statement.

3. Can I test this program online.

Thanks

I want to write a C program to test whether the character is uppercase, lowercase, digit or special symbol.

void main ()
{

char ch;

printf("\n Enter any character from the keyborad");

scanf("%c",&ch);

if (ch>=65&&ch<=90)

printf(" \n the character is uppercase);

if(ch>=91&&ch>=122)

printf(" \n the character is lowercase);

if(ch>=48&&ch<=57)
printf("\n You entered a digit );

}

My question how to print whether the character is a special symbol. I don't know this. Please can anyone point out.

Thanks

This code is specific to the ASCII character set. It would not work with other character sets. There are functions available such as isupper(), islower(), isdigit() etc that you can use for this exercise. These functions are available with the ctype.h header file.

1. Whether I can use ASCII code for to print special symbols, like I have done above in 3 cases.

What are special characters? Are they the glyph characters that are neither digits nor latin alphabet characters? Are they control characters? What about extended characters? All of the above? You need to specify what you think a special character is before you can test for one.

2. Are there braces missing in my program after if statement.

That is something your compiler will tell you. :)

3. Can I test this program online.

I do not know of a way to compile and run a program online, but you can compile your code here. Be sure to set it to compile as C though. It defaults to C++.

This code is specific to the ASCII character set. It would not work with other character sets.

Which ones? The only one I know of is EBCDIC, and EBCDIC is not common. Everything else that supports the latin characters is compatible with 7 bit ASCII, AFAIK.

For readability I would use character constants instead of straight values:

if (ch >= 'A' && ch <= 'Z')
{
    printf("The character is uppercase\n");
}
else if (ch >= 'a' && ch >= 'z')
{
    printf("The character is lowercase\n");
}
else if (ch >= '0' && ch <= '9')
{
    printf("You entered a digit\n");
}

It is a safe assumption that this is a homework assignment and the is*() functions are not allowed or have not been covered yet. So it is fine to say they exist and recommend them, but you should also offer an alternative that matches the level of the program. Having to worry about portability, internationalization, and all of that junk so soon will just scare people off. ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.