Reading lines of text from (large) file?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/02/2003 at 17:55, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 8.012
Platform: Windows ;
Language(s) : C.O.F.F.E.E ;---------
The code needs to read in a file and parse it, line by line. But, there is no ReadLine() function, so I created one myself. Let me know if this might work or if there is another approach.
filelength is set to basefile->GetLength() right after calling basefile->Open() in another function.FileParser::ReadLine(basefile) { // Read in a line of text (until EOL) from file var onechar ; var line; // Keep reading until EOL or EOF is reached while (basefile->GetPosition() < filelength) { onechar = basefile->ReadString(1, GE_XBIT); if (onechar != '\n') line = stradd(line, onechar); else return TRUE; } // Unexpected EOF return FALSE; }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 08/02/2003 at 02:27, xxxxxxxx wrote:
This will fail for some combinations of LF and CR. (0x0A and 0x0D.) The three possibilities are CRLF (pc), CR (mac) and LF (unix). The easiest way is to consider CR (0x0d) as newline and always ignoring LF (0x0a). This won't work with unix files, but these aren't very common on C4D's platforms. (If you want to handle unix files as well, I guess you'll have to maintain some state variables.)