Amazon.com Widgets attempted answer to exercise 16-4
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 24, 2014, 04:49:00 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Answers to Exercises
| | |-+ Chapter 16 (Moderator: sgg_admin)
| | | |-+ attempted answer to exercise 16-4
Pages: [1] Go Down
Print
Author Topic: attempted answer to exercise 16-4 (Read 747 times)
mdeh
Full Member
***
Posts: 166






on: February 18, 2009, 08:17:38 PM

I am not sure if this is what was meant, but here goes.
Note: Assumes "Cat in hat" passed as argument on command line.



Code: (Objective-C)
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
#import <Foundation/NSProcessInfo.h>
#import <Foundation/NSDictionary.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSProcessInfo *proc = [NSProcessInfo processInfo];
int x;
NSDictionary    *env = [proc environment];


NSLog(@"Usage: \"activeProcessorCount.\" Number of Active Processors: %u", [proc activeProcessorCount]);
NSLog(@"Usage: \"arguments\". Assumed \"Cat in hat\" in command line");
NSLog(@"Usage: \"[arguments count]\" %u", [[proc arguments]count]);
NSArray *args  = [proc arguments];
NSLog(@"Iterate through NSArray \"arguments\"");
for ( x = 1; x < args.count; x ++)
NSLog(@"%@",  [args objectAtIndex: x]  );
NSLog(@"Iterate through environment");
for (id key in env)
{
NSLog(@"key: %@, value: %@", key, [env objectForKey:key]);
}
NSLog(@"Usage:\"globally Unique String\": %@", [proc globallyUniqueString]);
NSLog(@"Usage:\"host name\": %@", [proc hostName]);
NSLog(@"Usage:\"operating system\": %u", [proc operatingSystem]);
NSLog(@"Usage:\"operating system name\": %@", [proc operatingSystemName]);
NSLog(@"Usage:\"operating system version string\": %@", [proc operatingSystemVersionString]);
NSLog(@"Usage:\"physical memory\": %llu", [proc physicalMemory]);
NSLog(@"Usage:\"processIdentifier\": %u", [proc processIdentifier]);
NSLog(@"Usage:\"process name\": %@", [proc processName]);
NSLog(@"Usage: \"ProcessorCount.\" Number of Processors: %u", [proc processorCount]);

    [pool drain];
    return 0;
}

Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.