• 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: [Newbie] Basic file handling questions...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Newbie] Basic file handling questions...


  • Subject: Re: [Newbie] Basic file handling questions...
  • From: "Erik M. Buck" <email@hidden>
  • Date: Thu, 8 Nov 2001 14:06:27 -0600

If your files are short, you can do the folowing:

NSString *fileText = [[NSString alloc] initWithContentsOfFile:somePath];
NSArray *individualLines = [fileText componentsSeparatedByString:@"\n"];
[fileText release];

// individualLines is now an autoreleased array containing one line at each
index in the array




If your files are long, you can use NSScanner or the technique you are
already using.

You can also always use stdio.

FILE *file = fopen(somePath, "r");

if(NULL != file)
{
char buffer[SOME_LARGE_SIZE];

while(NULL != fgets(buffer, SOME_LARGE_SIZE - 1, file)
{
// do something with the one line of text in buffer
}

fclose(file);
}

----- Original Message -----

References: 
 >[Newbie] Basic file handling questions... (From: Martin-Luc Girard <email@hidden>)

  • Prev by Date: Re: [Newbie] Basic file handling questions...
  • Next by Date: Re: Type?
  • Previous by thread: Re: [Newbie] Basic file handling questions...
  • Next by thread: trouble with array to string conversion
  • Index(es):
    • Date
    • Thread