• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Reading in dictionary from txt file: options for speed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading in dictionary from txt file: options for speed


  • Subject: Re: Reading in dictionary from txt file: options for speed
  • From: Greg Guerin <email@hidden>
  • Date: Thu, 16 Apr 2009 16:43:29 -0700

Miles wrote:

    NSString *searchStr        = @"\njoy\n";
    NSData *strData            = [searchStr
dataUsingEncoding:NSUTF8StringEncoding];
    const char *strBytes    = [strData bytes];

Think about what you're doing here, then look at the NSString method - UTF8String.


Also, think about whether dataUsingEncoding: includes or excludes a terminating null. For example, if searchStr were assigned @"", what is the length of the resulting strData, and exactly what does [strData bytes] return? A combination of referring to reference docs and some experimenting is the usual approach here.

Next, consider the above in light of the args to strstr(), which are expected to be null-terminated C-style strings.

Finally, consider what happens if searchStr isn't found. I urge you to try it with a searchStr assigned a misspelled word like @"spelchek".

If it seems like I'm asking you to debug and understand your own code without asking the list for the complete answer, you're right. This is a pretty elementary example to work on, and there's no substitute for being able to figure it out for yourself. If you can't debug this one without direct assistance, you will be lost at sea when the debugging gets harder (and it WILL get harder).

  -- GG
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Reading in dictionary from txt file: options for speed
      • From: Miles <email@hidden>
  • Prev by Date: Re: Create folder in protected directory
  • Next by Date: Re: Reading in dictionary from txt file: options for speed
  • Previous by thread: Re: Reading in dictionary from txt file: options for speed
  • Next by thread: Re: Reading in dictionary from txt file: options for speed
  • Index(es):
    • Date
    • Thread