Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jamesapp

macrumors 6502a
Original poster
Mar 7, 2008
544
0
i am working on exercise 3 from chapter 19 from a programming book by Stephen Kochan

here is the exercise from the book:

Code:
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

Code:
#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?
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
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.

-Lee
 

skochan

macrumors regular
Apr 1, 2006
150
0
California
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.
-Lee

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

Steve Kochan
 

krye

macrumors 68000
Aug 21, 2007
1,606
1
USA
Yes, sorry. that URL is no longer valid... That's the cause of the problem.

Steve Kochan

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.