Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Read a text file with inconsistant delimiter

Hi all,

Does anyone knows how to read some data if the data is tab delimited and the tabbing is not constant? i.e. the 1st & 2nd fields may be separated by a tab while the 3nd & 4th fields may be separated by a double tab.

I have tried to read the data by the field length but realised that C programs treat "Tab" as a character and hence the data are read incorrectly.
E.g.

row1_1st 2nd 3rd 4th
row2_1st_more 2nd 3rd_more_stuff 4th

Note that the data of row 1 has tabs embedded in between the fields. But in row 2, some fields are not separated by . So I can only read the fields using fixc field length. But how do I read the data using fix field length without treating the as a character?


Thanks and really appreciate your attention!

Comments

  • Hesham.E.Hesham.E. Member Posts: 10
    Hello,
    scanf() or fscanf() can solve your problem.

    : Hi all,
    :
    : Does anyone knows how to read some data if the data is tab delimited and the tabbing is not constant? i.e. the 1st & 2nd fields may be separated by a tab while the 3nd & 4th fields may be separated by a double tab.
    :
    : I have tried to read the data by the field length but realised that C programs treat "Tab" as a character and hence the data are read incorrectly.
    : E.g.
    :
    : row1_1st 2nd 3rd 4th
    : row2_1st_more 2nd 3rd_more_stuff 4th
    :
    : Note that the data of row 1 has tabs embedded in between the fields. But in row 2, some fields are not separated by . So I can only read the fields using fixc field length. But how do I read the data using fix field length without treating the as a character?
    :
    :
    : Thanks and really appreciate your attention!
    :

Sign In or Register to comment.