Read a text file line by line?
Is it possible to read a text file line by line or some way split up the lines once read out of a text file?
Thanks
Thanks
Yes. For example, http://www.opengroup.org/sud/sud1/xsh/fgets.htm
(Dec 13, 2011 10:02 PM)ThemsAllTook Wrote: Yes. For example, http://www.opengroup.org/sud/sud1/xsh/fgets.htm
Thank you very much, I forgot to note that I'm using Objective C and this is for iOS.
If you can't get ThemsAllTook's answer to work I'm quite sure you can find what you are searching for here:
NSString Class Reference
Or by googling: "Cocoa file to string" & "NSString split into lines"
NSString Class Reference
Or by googling: "Cocoa file to string" & "NSString split into lines"
McSpider
if you know that the lines are all of the same length (suppose 30 chars) you can use fscanf("%30c",&string);
I ended up figuring it out. I just used this:
NSArray *lines = [fileContent componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
Below it I loop through the array and separate it out into strings.
NSArray *lines = [fileContent componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
Below it I loop through the array and separate it out into strings.
If your input file is large enough, you will also want to consider using an input stream buffer. This will allow you to read only a portion of the file so that you don't dump the entire file into memory at once.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Fast, 2d, line of sight? | TimMcD | 1 | 3,370 |
Dec 25, 2009 10:46 PM Last Post: Skorche |
|
| Applets from the Command Line | merrill541 | 0 | 1,916 |
Nov 23, 2008 12:44 PM Last Post: merrill541 |
|
| Command line arguments | anthony | 3 | 3,096 |
Dec 22, 2007 04:12 AM Last Post: OneSadCookie |
|
| fgets is only reading part of the line | Joseph Duchesne | 3 | 2,813 |
Feb 10, 2006 01:23 AM Last Post: Taxxodium |
|
| Multiple Defines on One Line | unknown | 10 | 5,462 |
Jul 31, 2005 01:21 PM Last Post: OneSadCookie |
|

