C file input

This is a discussion on C file input within the C Programming forums, part of the General Programming Boards category; Is there a C function that can set deliminators?I'm trying to read in a string token at a time from ...

  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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,270
    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
    Aia
    Aia is offline
    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, 01:44 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-22-2008, 12:19 AM
  3. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 02: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

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