![]() |
|
Read a text file line by line? - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Game Programming Fundamentals (/forum-7.html) +--- Thread: Read a text file line by line? (/thread-9621.html) |
Read a text file line by line? - jdunehew - Dec 13, 2011 09:47 PM 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 RE: Read a text file line by line? - ThemsAllTook - Dec 13, 2011 10:02 PM Yes. For example, http://www.opengroup.org/sud/sud1/xsh/fgets.htm RE: Read a text file line by line? - jdunehew - Dec 13, 2011 10:13 PM (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. RE: Read a text file line by line? - McSpider - Dec 13, 2011 10:50 PM 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" RE: Read a text file line by line? - sefiroths - Dec 15, 2011 03:36 AM if you know that the lines are all of the same length (suppose 30 chars) you can use fscanf("%30c",&string); RE: Read a text file line by line? - jdunehew - Dec 15, 2011 11:57 AM 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. RE: Read a text file line by line? - Blacktiger - Dec 29, 2011 11:54 AM 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. |