Reading csv files: one column files

 

Hoping this message could be of any help after having lost two days working on understanding what was wrong...

Apparently there is no way to create the simplest possibile application to read a 1-column csv file with n-rows of data. Any 2 ore more columns csv file will be read with no problems, but not one with a single column. I have not been able to understand the reason why, but possibly there is some kind of conflict when the pointer reaches the end of each single line. 

I found the only possibile shortcut to this problem is adding a fake second column to the original file, so both data, the useful one and the fake, will be read and processed into the code. Then you would only consider the first data on each row and disregard the second one.

I'm adding a short code to help you out with this. 

I hope it helps you save precious time.

 

 

handle=FileOpen(filename,FILE_CSV|FILE_READ,',');

         a=0;

   

         while(FileIsEnding(handle)==false)                             //reads file and fills array with data from each cell in the file 

         {

fData[a,0]=FileReadString(handle);

               fData[a,1]=FileReadString(handle);

               a++;

 

       if (FileIsEnding(handle)==true) break;

         }  

FileClose(handle); 

 
rubborto:

Hoping this message could be of any help after having lost two days working on understanding what was wrong...

Apparently there is no way to create the simplest possibile application to read a 1-column csv file with n-rows of data. Any 2 ore more columns csv file will be read with no problems, but not one with a single column. I have not been able to understand the reason why, but possibly there is some kind of conflict when the pointer reaches the end of each single line. 

I found the only possibile shortcut to this problem is adding a fake second column to the original file, so both data, the useful one and the fake, will be read and processed into the code. Then you would only consider the first data on each row and disregard the second one.

I'm adding a short code to help you out with this. 

I hope it helps you save precious time.

<CODE DELETED>

Please read some other posts before posting . . .

Please   edit   your post . . .    please use the   SRC   button to post code: How to use the   SRC   button. 

 
rubborto: Apparently there is no way to create the simplest possibile application to read a 1-column csv file with n-rows of data.

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. I've never had any problem.
       int         handleOPT      = FileOpen(nameOPT, FILE_CSV|FILE_READ, '~');
       if(handleOPT < 1) ...
       while(true){   // Not EOF
          string   line = FileReadString(handleOPT);   if(line == "") break;
    
    With the exception of file is ending. The last line is always empty, so that's my exit.