Reading first column in a file and creating new files...

marconi_07's Avatar, Join Date: Aug 2009
Light Poster
Hi,

Could you please assist me with the 'C' code for the following :-

I have a file called Test.txt.


I) Test.txt
---------

A,BC,DE,HI,00,11
A,DE,HI,JK,23,24
A,XX,YY,YU,40,95
B,CD,EF,GH,11,22
B,JJ,KK,JU,45,89
C,DE,FG,HI,22,33
C,EF,GH,IJ,77,88
D,EF,GH,IJ,33,44
D,FG,HI,JK,44,55


Need to read the first column of the file and create files such that for each change in the first column, a new file is created with the filename as first column.ref.

That is for above file, 4 Files are created as each time the first column changes, a new file is created. The 4 files generated are as follows:-


II)

1) A.ref
------

BC,DE,HI,00,11
DE,HI,JK,23,24
XX,YY,YU,40,95


2) B.ref
------

CD,EF,GH,11,22
JJ,KK,JU,45,89


3) C.ref
------

DE,FG,HI,22,33
EF,GH,IJ,77,88


4) D.ref
------

EF,GH,IJ,33,44
FG,HI,JK,44,55



Best Regards,
Marconi.
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
How far have you got and where are you stuck?
Have you written code to open the input file and read the lines, with minimal extra code, for example just display the lines to the screen?