LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

splitting out columns of data from a text file

Hi,

 

Urgent help/direction required to do the following.

 

I have 6 serial numbers and one text file, attached (for example xs0000_G1_7.6V_pre.log).

 

In the text file there are 48 column, each column is 4 hex digits long. In the file attached the first 8 columns have data.

 

I need to make 6 new files, <S/N>.txt, containing 8 columns of data, with the last file containing the last 8 columns and the first <S/N>.txt having the first 8 columns of data.

 

What do you think?

 

Thanks

Simon

   

0 Kudos
Message 1 of 4
(3,948 Views)

I suppose you'll have to tokenize the lines (strtok) as they are read, i'd put each column piece in an array, then send those pieces to the file pointers.

 

Look at

FILE *fileHandle;

 

fileHandle=fopen(filename,"w+");


..

for(...){

 

fprintf(fileHandle,"formatted msg, %s\n",columnArray[i]);

}

...

statusReturned=fclose(fileHandle);

0 Kudos
Message 2 of 4
(3,937 Views)

Since data in the file are fixed-lenght, you could:

 

Open the source file
Open 8 destination files

Do:
   Read a line
   Loop this 8 times:
      Read 40 characters (8 data 4 characters long + 1 space)
      move to a destination file
   End-of-loop
Until end-of-source-file

Close destination files
Close source file

 

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 4
(3,930 Views)

 

Hi,

 

Thanks for the help and direction.

 

Attached is how I got around it, I am sure it could be cleaned up, if I knew how, but this works so it is a good base to continue as there will be a lot of differentI/P files to be handled.

 

Thanks

Simon

0 Kudos
Message 4 of 4
(3,921 Views)