exersise 3 chapter19 kochan book

Discussion in 'Mac Programming' started by jamesapp, May 21, 2008.

  1. jamesapp macrumors 6502a

    Mar 7, 2008
    i am working on exercise 3 from chapter 19 from a programming book by Stephen Kochan

    here is the exercise from the book:

    The glossary in Appendix A has been stored online as a traditional property list at the URL http://www.kochan-wood.com/examples/glossary.pl Write a program to read the glossary into a dictionary object and then display its contents.
    here is the program which i got off this site i called it exc3chap19.m

    #import <Foundation/NSObject.h>
    #import <Foundation/NSString.h>
    #import <Foundation/NSDictionary.h>
    #import <Foundation/NSEnumerator.h>
    #import <Foundation/NSArchiver.h>
    #import <Foundation/NSAutoreleasePool.h>
    #import <Foundation/NSURL.h>
    #import <stdio.h>
    int main (int argc, char *argv[])
            NSAutoreleasePool    *pool = [[NSAutoreleasePool alloc] init];
            NSDictionary  *glossary;
            NSEnumerator  *keyEnum;
            NSString      *url = @"http://www.kochan-wood.com/examples/glossary.pl";
            id            key;
            glossary = [NSDictionary dictionaryWithContentsOfURL: 
                             [NSURL URLWithString: url]];
            keyEnum = [glossary  keyEnumerator];
            while ( (key = [keyEnum  nextObject]) != nil ) 
                    printf ("%s: %s\n", [key UTF8String], 
                                    [[glossary objectForKey: key] UTF8String]);
            [pool release];
            return 0;
    the program compiled to an executable without any problems.
    just wondering what this program is supposed to do?
    i ran the program in terminal and it appeared to do nothing.
    is there a way to view this property list?
  2. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    if it did nothing, it probably didn't work. The only case where no output is the proper behavior is if the property list is completely empty. I doubt seriously this was what was provided as the example property list.

    The program should display is:
    keyA: valA
    keyB: valB

    Assuming the list had two entries with keys keyA and keyB with values valA and valB.

    The URL there doesn't seem to point to a property list, it loaded a website for me, which seems quite unfortunate. I tried with curl to make sure it wasn't some browser detecting voodoo, but it still just came back as html. Perhaps the example is out of date, and you'll need to get a URL to some other property list to test this.

  3. skochan macrumors regular

    Apr 1, 2006
    Yes, sorry. that URL is no longer valid... That's the cause of the problem.

    Steve Kochan
  4. krye macrumors 68000


    Aug 21, 2007
    Wow, an answer from the man himself! Very nice!

    I am reading your book too. It's a very good read for the newbie who has no programming experience at all. Thanks.

Share This Page