untested:
int getCsvLines( const string fName, string &l[], int flag=0, ushort sepLine='\n') { // alternative to FileOpen uchar Bytes[]; return( FileLoad(fName, Bytes, flag) ? StringSplit(CharArrayToString(Bytes), sepLine, l) : 0); }
You can't use that because your rows length is variable (text file).
Just read in the lines until end of file, counting as you go.
Why do you need the count?
hello and thanks.
My interpretation of this:
the function "getCsvLines" can get the number of lines.
When I call the function, I believe I have to provide a number of parameters.
The first one is fName, ok I have this.
But what about the others?
string&[],int,ushort
Please let me know what I should provide for those.
Thanks!!
You can't use that because your rows length is variable (text file).
Just read in the lines until end of file, counting as you go.
Why do you need the count?
Hello and thanks,
why I need the count?
because later I will write content of the file to an array.
and I would like to make the size of the array dynamic - depending on the number of lines in the file.
When in doubt, think!
struct FileStructure{ int i; double d; string s; read(int h){ i=FileReadInteger(h); d=FileReadDouble(h); s=FileReadString(h); } }; ⋮ int h=FileOpen(…); if(h == INVALID_HANDLE) … FileStructure line; int count=0; while( !FileIsEnding(h) ){ line.read(h); ++count; } PrintFormat("File has %d lines", count);;
I gave you “a tip how to do this,” not working code. You should have already known how to do that.
The error is obvious. If you can't see it, stop trying to code until you learn the language.
Hello, I can see your point. Sorry, I am a week-end worrier. I will do as you said and continue to learn the language.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hello there, I would like to check, how many rows are in a file.
I am working with CSV files.
I have tried "file size", but it gives the size in terms of bites, not rows.
If you are aware of any trick, thanks in advance.
This is for MQL5.