Reading first column in a file and creating new files…

Home Forums C Programming Reading first column in a file and creating new files…

Viewing 1 reply thread
  • Author
    Posts
    • #2220
      GarnetHuynh
      Participant

      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.

    • #3601
      GWILouisaxwzkla
      Participant

      This seems to work:

Viewing 1 reply thread
  • You must be logged in to reply to this topic.