FileRead isn't working correctly - what can I do? - page 2

 
gooly:

Well,

if you use the mt4-file-finctions you ONLY can read x-bytes.

The carriage-return is just one char among the others - your editor simply does s.th different.

So if you read a bit of the file you don't know where is the and of you bit. May be it ends right in the middle of a token you are searching for.

To manage all this ... I think you can imagine..

Off the top of my head . . . read the file a chunk at a time into an array of strings, when the whole file is read go through the strings in the array one by one looking for the CR and break the strings down into single lines . . . I don't think that is too hard to do, is it ?
 
angevoyageur:
Did you look at existing code ? https://www.mql5.com/ru/code/10366

Thanks, didn't know that, but

1) all is in Russian I guess, which makes it hard to use and even more

2) this code will be trapped in the same way. This is what I found in its XMLParsingMQL4.mq4:

/// Ñ÷èòûâàåì Xml ôàéë FileName. Ïðîïóñêàåì çàãîëîâîê.
string XmlDocument(string FileName  ///< [in] Èìÿ ôàéëà
                   ) {
   string doc="";
   int Handle = FileOpen(FileName, FILE_BIN|FILE_READ);
   if(Handle!=-1) {
      doc = FileReadString(Handle,  FileSize(Handle) );
      GetStrUpTo(doc, EndOfXmlDeclarationStr);
   }
   return (doc);
}

So even here only 4k will be read...

Reason: