Separate text when reading text

This is a discussion on Separate text when reading text within the C Programming forums, part of the General Programming Boards category; I have a file that has the following layout Data:\t (tab)serial Should I use strtok to separate the Data:\t from ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    62

    Separate text when reading text

    I have a file that has the following layout

    Data:\t (tab)serial

    Should I use strtok to separate the Data:\t from the string I want or use something else?

    Code:
    #define DELIM_2 "Data:\t"
    
    char  *sep = strtok(filedata, DELIM_2);
    printf ("%s\n", sep);
    Doesn't seem to work.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    204
    Read a line from the file into a character buffer and use the strchr function from string.h to get a pointer to that tab.
    Code:
    char line[MAXLINE];
    /* read a line from the file into line */
    char *p = strchr(line, '\t');
    printf("%s\n", p + 1);
    You should check the return value of strchr just to make sure before attempting to use it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading text
    By Anator in forum C++ Programming
    Replies: 33
    Last Post: 01-30-2008, 11:13 AM
  2. reading a char at a time from text
    By dudeomanodude in forum C++ Programming
    Replies: 7
    Last Post: 01-29-2008, 11:27 AM
  3. reading from a text file help......
    By jodders in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2005, 11:51 AM
  4. Reading text file and structuring it..
    By Killroy in forum C Programming
    Replies: 20
    Last Post: 11-19-2004, 07:36 AM
  5. Reading Tab Separted Text files
    By Cathy in forum C Programming
    Replies: 1
    Last Post: 02-15-2002, 09:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21