Split a line by whilespace or tabcharacter (\t)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neeru29
    New Member
    • Feb 2009
    • 21

    Split a line by whilespace or tabcharacter (\t)

    Hi,

    I have file in while following line are present

    dir1 dir2 dir3 dir2 file1 file2
    dir1_file1 dir1_file2\tdir 2_file1 dir2_file2\tdir 3_file1
    ...
    ...

    reading a one line at a time from a file,

    i'm using the function strtok_r() to split the each line with delimiter whilespace and '\t' character.

    How can differentiate that 2 words are split by whitespace or '\t' character.

    Is there any work around for this.
    Plz let me know.

    Thanks.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I wouldn't use strtok. Instead examine each character of your search string using isspace. That will detect whitespace and since \t is whitespace, it will be detected by default. Then extract your token using strncpy.

    Comment

    Working...