Roger's example above seems only for a paragraph, or until a new line feed.
In my case I don't know how many paragraphs file has or how long each paragraph.
In your case it is very simple:
int start(){int val[3][3],i,j,handle;
handle=FileOpen("test.txt",FILE_READ);//try to open fileif(handle==-1)return(0);// if not existif(FileSize(handle)==0){FileClose(handle);return(0);}//if emptyfor(i=0;i<3;i++)for(j=0;j<3;j++){
val[i][j]=StrToInteger(FileReadString(handle));//read one variable//Print("Val",i,j," - ",val[i][j]);//You can print it to be sure}FileClose(handle);//close filereturn(0);}
In my case I don't know how many paragraphs file has or how long each paragraph.
In your case it is very simple:
Hello Roger,
Did you say that your previous example will working no matter how many are the paragraphs? In my real case, I don't know how many paragraphs is in the text file. I guess I need to re-read your code.
Thanks for the code. Im using it to read a text file in the form of "22 43 4554 123 12" for instance, but what I really need is to read a file in CSV format.
Hello all. I have a similar issue and hope you can help me with it.
I want to read all the elements of an array in a file. EX: "file.text" that contains (1,2,3,4,5,6,7)
After reading them, also I want to save those values into an array in the routine to modify them in a( for loop).
At the end of the loop, I want to save them again tothe "file.text" for later use and add one more slot to the array. EX: modified values after the for loop (10,20,30,40,50,60,70,new slot starting at =1)
If anyone can help me to solve this simple task, I will appreciate it a lot.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Roger's example above seems only for a paragraph, or until a new line feed.
In my case I don't know how many paragraphs file has or how long each paragraph.
In your case it is very simple:
In my case I don't know how many paragraphs file has or how long each paragraph.
In your case it is very simple:
Hello Roger,
Did you say that your previous example will working no matter how many are the paragraphs? In my real case, I don't know how many paragraphs is in the text file. I guess I need to re-read your code.
Thank you
Hi Roger,
Thanks for the code. Im using it to read a text file in the form of "22 43 4554 123 12" for instance, but what I really need is to read a file in CSV format.
Ive tried replacing
handle=FileOpen("test.txt",FILE_READ)
with
handle=FileOpen("test.csv",FILE_READ|FILE_CSV,',')
but apparently only the final value is read. Im sure Im missing something...
.
Try
handle=FileOpen("test.csv",FILE_READ|FILE_CSV,' ') ; // last parameter is a space, as it appears your delimiter is a space
Is there some reason the space " " can not be specified as delimiter in FileOpen()? Nobody seemed to have suggested this.
[Edit:] it has, i can see it now after drinking some coffee.
handle=FileOpen("test.csv",FILE_READ|FILE_CSV,',')
but apparently only the final value is read. Im sure Im missing something...
Hello all. I have a similar issue and hope you can help me with it.
I want to read all the elements of an array in a file. EX: "file.text" that contains (1,2,3,4,5,6,7)
After reading them, also I want to save those values into an array in the routine to modify them in a( for loop).
At the end of the loop, I want to save them again tothe "file.text" for later use and add one more slot to the array. EX: modified values after the for loop (10,20,30,40,50,60,70,new slot starting at =1)
If anyone can help me to solve this simple task, I will appreciate it a lot.
Thanks in advance.
Simple task ?
Why do they always say that ?
Is it easy (or difficult) to …? - General - MQL5 programming forum
Simple task ?
Why do they always say that ?