OK, please help me see the error


#1

Here’s what I’ve got. Can’t get any log statements, though the code compares to others’ code. I’m not seeing something.

I tried the nested loops right off, but since they didn’t work, I went about exploring other possibilities with enlightening results that were nonetheless inapplicable to the assignment at hand.

So, fellow coders, please cast your eye(s) over this code and tell me what I’m not seeing, if you’d be so kind. FYI, running Xcode 4.3 on OSX 10.7.2.

Thanks. Here’s the code:

//
// main.m
// challenge8

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{ @autoreleasepool

{       // Read in two files.
    
    NSString *nameString = [NSString stringWithContentsOfFile:@"/usr/share/dict/propernames" 
                                    encoding:NSUTF8StringEncoding error:NULL];  
    
    NSString *wordString = [NSString stringWithContentsOfFile:@"usr/share/dict/words"
                                      encoding:NSUTF8StringEncoding error:NULL];
    
        // Break these two files into two arrays of strings
    NSArray *names = [nameString componentsSeparatedByString:@"\n"];
    NSArray *words = [wordString componentsSeparatedByString:@"\n"];

    
    for (NSString *n in names) 
    {
        for(NSString *w in words)
        {
            if ([w caseInsensitiveCompare:n] == NSOrderedSame) 
             {
                 NSLog(@"%@ matches %@", n, w);
             }
        }
    }
}        

return 0;

}


#2

It looks reasonable enough at a casual glance, but you’re missing an initial forward slash on the path to /usr/share/dict/words. Perhaps that’s sufficient to fix it.


#3

I had to throw it into Xcode to find it, but you are missing the solidus at the beginning of the path to the words file. Once you stick a / on the front of the path it works.

I figured this out by tossing a breakpoint in after the arrays are created. When it stopped there I could see that the wordlist string and array were nil.


#4

Thank you very much, friends. That was it. Just couldn’t see it,

I appreciate your taking a moment to enlighten me.

:slight_smile: