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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Is the 2.66 GHz 12 Core worth it? Fesco Mac Pro 10 Dec 1, 2011 02:14 PM
Kochan 2.0 Exercise 11-3 mdeh Mac Programming 4 Jan 26, 2009 02:22 PM
Kochan 2.0 Exercise 10-6 mdeh Mac Programming 2 Jan 25, 2009 11:46 AM
Kochan 2.0 Exercise 10-2 ....a question mdeh Mac Programming 1 Jan 24, 2009 08:46 PM
Kochan 2.0 Exercise 8-7 Possible with NSLog? mdeh Mac Programming 3 Jan 17, 2009 09:04 PM


All times are GMT -5. The time now is 04:11 AM.

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

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