copying a number from a text document

 
hii friends, suppose i have a text file with some rabdom numbers only, only one number in each line.
10
500
350
457
1385
57
3987
4532


something like above. I want to copy the second last number. In this case 7th number. Remember we don't know which numbers are there and how many numbers are there. I just want to find the second last number. Any help please...

 
  1. If there are a reasonable number of lines (under millions) you can read each line and add to an array and you can access any element.
  2. Otherwise, just remember the last two.
    int last, prev;
    ⋮
    while(…){ prev = last; last = FileReadNumber(h); }
  3. Or the last n:
    int iLast=0, array[]; ArrayResize(array,n);
    ⋮
    while(…) array[--last % n] = FileReadNumber(h);
    #define prev(i) array[ (last+i) % n ] // last=prev(0)
 
William Roeder:
  1. If there are a reasonable number of lines (under millions) you can read each line and add to an array and you can access any element.
  2. Otherwise, just remember the last two.
  3. Or the last n:

ok. Now I am just trying to read all the numbers( 1660 numbers) from a csv file and print. But it only printing the last 205 numbers only. what is wrong with me?

//+------------------------------------------------------------------+
//|                                                        test1.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//#property strict
#property script_show_inputs
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {

  
  int FH=FileOpen("file.csv",FILE_CSV|FILE_WRITE|FILE_READ|FILE_SHARE_READ);
  
  
  
   
      while(!FileIsEnding(FH)) 
        { 
     
           double  num =FileReadNumber(FH);
      
       
      
           PrintFormat(num);
             
       }
  
  
    FileClose(FH);
  
 } 
  
   
   
  
//+------------------------------------------------------------------+
 
Clement Chand C S:

ok. Now I am just trying to read all the numbers( 1660 numbers) from a csv file and print. But it only printing the last 205 numbers only. what is wrong with me?

Check the log for the prints, not just the tab.

 
Clement Chand C S:

ok. Now I am just trying to read all the numbers( 1660 numbers) from a csv file and print. But it only printing the last 205 numbers only. what is wrong with me?

Please ignore the above post. When I opened log file, all numbers are there. Don't know why most of the numbers are not showing in the experts tab!!.


Anyway thanks for your help friend....

 
Keith Watford:

Check the log for the prints, not just the tab.

ha ha yes dear i just found it.