Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8159021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:47:22+00:00 2026-06-06T17:47:22+00:00

Sorry in advance for this being such a beginner question. Here are the steps

  • 0

Sorry in advance for this being such a beginner question. Here are the steps of what I’m trying to do:

  1. Read two text files (unix word list files for proper names and
    regular words)
  2. Separate the text into string
  3. Place the separated strings into an array for each list
  4. Compare the arrays and count the number of matches

For whatever reason, this code continually returns null matches. What might I be doing? Thanks a ton for any help.

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

    @autoreleasepool {

        // Place discrete words into arrays for respective lists
        NSArray *regularwords = [[NSString stringWithContentsOfFile:@"/usr/dict/words" encoding:NSUTF8StringEncoding error:NULL] componentsSeparatedByString:@"\n"];
        NSArray *propernames = [[NSString stringWithContentsOfFile:@"/usr/dict/propernames" encoding:NSUTF8StringEncoding error:NULL] componentsSeparatedByString:@"\n"];

        // The compare and count loop
        NSInteger *counter;
        for (int i = 0; i < [propernames count]; i++) {
            NSString *stringFromRegularWords = [regularwords objectAtIndex:i];
            NSString *properNamesString = [propernames objectAtIndex:i];
            if ([properNamesString isEqualToString:stringFromRegularWords]) {
                counter++;
            }
        }
        // Print the number of matches
        NSLog(@"There was a total of %@ matching words", counter);
    }
return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:47:23+00:00Added an answer on June 6, 2026 at 5:47 pm

    You’re doing objectAtIndex:i, expecting the words to be in exactly same indexes in both files. What you should probably do is add entries from one of the files to an NSMutableSet and then check for membership that way.

        // Place discrete words into arrays for respective lists
        NSArray *regularwords = [[NSString stringWithContentsOfFile:@"/usr/dict/words" encoding:NSUTF8StringEncoding error:NULL] componentsSeparatedByString:@"\n"];
        NSArray *propernames = [[NSString stringWithContentsOfFile:@"/usr/dict/propernames" encoding:NSUTF8StringEncoding error:NULL] componentsSeparatedByString:@"\n"];
    
        // Add each of the words to a set so that we can quickly look them up
        NSMutableSet* wordsLookup = [NSMutableSet set];
        for (NSString* word in regularwords) {
             [wordsLookup addObject:word];
        }
    
        NSInteger *counter;
        for (NSString *properName in propernames) {
            // This efficiently checks if the properName occurs in wordsLookup
            if ([wordsLookup containsObject:properName]) {
                counter++;
            }
        }
    

    Note that my example also uses “fast enumeration,” i.e. the for ... in syntax. While not necessary to solve your problem, it does make the code shorter and arguably faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry in advance that this might be a little challenging to read... I'm trying
Sorry in advance everyone for this question as I know the cascading select boxes
Sorry in advance as this question is similar (but not the same!) to others.
I'm sorry in advance if this question is flawed. I'm pretty new to databases(I
First of all, I'm sorry about the feedback-nature of this question. I'm trying to
I am new to web application development, so sorry in advance if this question
Sorry in advance if this has been answered, I've searched repeatedly here and the
Sorry in advance if this is a really basic Matrix/OpenGl question. I have a
I'm not exactly sure how to word this question, so sorry in advance for
I'm sorry in advance if this question is really weird. I am sending data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.