1. Ask for a single character to be typed from the keyboard. Analyze the
character and print out a message that it is:
- an alphabetic character (a–z or A–Z)
- a digit (0–9) or
- a special character (anything else)
* Tried a couple of ways of using a switch statement to code this problem just havent been able to figure out an efficient way, the exercise wants me to use an "if" or a "switch statement". I would appreciate your perspective and insight on how to takle this problem...
thank you
Arod
More details...
Code:
#include <stdio.h>
int main (int argc, const char * argv[])
{
char let;
printf("Please Insert a single character here: \n");
scanf("%c",&let);
switch(let)
{
case '0':case'1':case'2':case'3':case'4':case'5':case'6':case'7':case'8':case'9':
printf("You Entered a Digit from 0-9\n");
break;
case 'a':case'b':case'c':case'd':case'e':case'f':case'g':case'h':case'i':case'j':
case 'A':case'B':case'C':case'D':case'E':case'F':case'G':case'H':case'I':case'J':
case 'k':case'l':case'm':case'n':case'o':case'p':case'q':case'r':case's':case't':
case 'K':case'L':case'M':case'O':case'P':case'Q':case'R':case'S':case'T':case'U':
printf("You Entered a Character from A-Z\n");
break;
default:
printf("Special Character");
}
return 0;
}
I am going try and do it as an if statement, any suggestions?