Thread: C file input

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    3

    C file input

    Is there a C function that can set deliminators?I'm trying to read in a string token at a time from a file that is separated by space.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by potato View Post
    Is there a C function that can set deliminators?I'm trying to read in a string token at a time from a file that is separated by space.
    There is a standard function strtok() which does this (allowing you to choose which characters to use as delimiters), but it has several serious drawbacks.

    A better method might be to read single characters at a time from the file, using fgetc(), and store them in a buffer. Continue to do this until you reach a delimiter character, at which point you are done with one token and can begin the next one. Make sure that if there is more than one delimiter character in a row, that you consume all of them, so that you don't get bogus characters at the beginning of the next token.

  3. #3
    Beautiful to C Aia's Avatar
    Join Date
    Jun 2007
    Posts
    124
    When the eagles are silent, the parrots begin to jabber. ~Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  4. Totally confused on assigment using linked lists
    By Uchihanokonoha in forum C++ Programming
    Replies: 8
    Last Post: 01-05-2008, 04:49 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM