Thread: Separate text when reading text

  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, 12:13 PM
  2. reading a char at a time from text
    By dudeomanodude in forum C++ Programming
    Replies: 7
    Last Post: 01-29-2008, 12:27 PM
  3. reading from a text file help......
    By jodders in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2005, 12:51 PM
  4. Reading text file and structuring it..
    By Killroy in forum C Programming
    Replies: 20
    Last Post: 11-19-2004, 08:36 AM
  5. Reading Tab Separted Text files
    By Cathy in forum C Programming
    Replies: 1
    Last Post: 02-15-2002, 10:28 AM