Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Reading first column in a file and creating new files... (http://www.go4expert.com/forums/reading-column-file-creating-files-t18971/)

marconi_07 10Aug2009 18:23

Reading first column in a file and creating new files...
 
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.

xpi0t0s 10Aug2009 20:33

Re: Reading first column in a file and creating new files...
 
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?


All times are GMT +5.5. The time now is 22:28.