hi guys,
i'm re-learning objective-c (got book) , i'm stuck on 1 exercise. can recreate easy enough in c++ not in objective-c.
supposed find every occurrence of word in proper names list found in /usr/share/dict/propernames found in /usr/share/dict/words.
example book gives "glen" , "glen" since glen persons name , noun.
have tried sorts of stuff , keep getting weird results. checked ensure arrays holding proper names list , words list correct, comparisons not working correctly , i'm not sure why.
can fresh eyes spot doing wrong? nsorderedsame not work how think works?
code:#import <foundation/foundation.h> int main (int argc, const char * argv[]) { @autoreleasepool { //read in file string 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 array of strings nsarray *names = [namestring componentsseparatedbystring:@"\n"]; nsarray *words = [wordstring componentsseparatedbystring:@"\n"]; //this things go wrong for(nsstring *w in words) { for(nsstring *n in names) { if([w caseinsensitivecompare:n] == nsorderedsame) { nslog(@"%@ = w, %@ = n", w, n); //this comparison produces weird results! } } } } return 0; }
edit: i'm not sure if found problem or not, appears dictionary list contains proper names well! have been correct entire time 0_0! i'll leave incase else can spot wrong.
edit2: oops forgot other comment. results should names "glen , glen" or "brook" , brook" showing i'm pretty sure because common names in dictionary list. see aaron in dictionary list.
1. describe expected happen.
2. describe happened.
"weird results" not description of happened. @ least not in useful way. example output useful.
should find specific counter-example, such name winston, isn't in words list. if don't see winston in output, should reconsider "weird". (i picked winston because it's near end when cat'ed propernames file. doesn't appear when grep -i words list.) in general, it's idea run tests using small sample data produces known results, before running on general data.
also, perfect case nsset. read personal names, convert lower-case, add nsset. can read list of words , more check whether it's name or not.
same results reading words nsset , testing names, @ relative sizes of sets , see smaller.
code:wc /usr/share/dict/words wc /usr/share/dict/propernames
Forums Macs Mac Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
No comments:
Post a Comment