Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 27, 2009, 12:27 AM   #1
mdeh
macrumors 6502
 
Join Date: Jan 2009
Kochan 2.0 Exercise 12-6

Quote:
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;
}
mdeh is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Learning Obj C - Kochan or Big Nerd Ranch? afousek iPhone/iPad Programming 4 Apr 26, 2014 01:45 PM

Forum Jump

All times are GMT -5. The time now is 07:28 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC