1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'C' started by marconi_07, Aug 10, 2009.

  1. marconi_07

    marconi_07 New Member

    Joined:
    Aug 10, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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?
     

Share This Page