Write a macro called IS_DIGIT that gives a nonzero value if a character is a digit 0 through 9. Use this macro in the definition of another macro called IS_SPECIAL, which gives a nonzero result if a character is a special character (that is, not alphabetic and not a digit). Be sure to use the IS_ALPHABETIC macro developed in Exercise 5.
Any feedback is welcome.
Code:
#import <Foundation/Foundation.h>
#define IS_UPPER_CASE(c) (((c) >= 'A') && ((c) <= 'Z'))
#define IS_LOWER_CASE(c) (((c) >= 'a' ) && (( c) <= 'z'))
#define IS_ALPHABETIC(c) (IS_UPPER_CASE(c) || IS_LOWER_CASE(c))
#define IS_DIGIT(c) ((c) >= '0') && ((c) <= '9')
#define IS_SPECIAL(c) (!IS_ALPHABETIC(c) ) && ( !IS_DIGIT(c) )
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
char c = 'w', d = '0', e = '\t';
if (IS_SPECIAL(c))
NSLog(@"%c is a special char eg tab, whitespace", c);
else
NSLog(@"%c is not a special char eg tab, whitespace", c);
if (IS_SPECIAL(d))
NSLog(@"%c is a special char eg tab, whitespace", d);
else
NSLog(@"%c is not a special char eg tab, whitespace", d);
if (IS_SPECIAL(e))
NSLog(@"%c is a special char eg tab, whitespace", e);
else
NSLog(@"%c is not a special char eg tab, whitespace", e);
[pool drain];
return 0;
}