Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
May 22, 2018, 04:07:09 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
Author Topic: attempted answer to exercise 16-4  (Read 1355 times)
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;

Pages: [1]   Go Up
Jump to:  

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 ゥ 2009 All rights reserved.