Thread: File I/O Read and Check

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

    File I/O Read and Check

    Hi, I need help with reading and checking from a binary file. I want to read until a i reach a certin byte. Heres an example...

    File:

    ...291....09...../...0927.. [ect]

    EOF

    I want to read till the '/' and leave the pointer at that position.

    Can anyone help me?

    Thanks, ~rab

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    use fgetc() in a loop -- it returns only 1 character at a time, then just check each byte read.

    actually, since this is c++ board, not C, you should use fstream's get() method.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    16
    Thanks, I'll try it out.

  4. #4
    Registered User Kurisu's Avatar
    Join Date
    Feb 2006
    Posts
    62
    Perhaps these might serve as an alternative:

    Code:
    istream& get (char* s, streamsize n, char delim );
    Reads up to the delim in your case '/', but doesn't read it, rather leaves the pointer on it for the next read.
    -------------------------------------------------------------------------------------
    or

    Code:
    istream& getline (char* s, streamsize n, char delim );
    Reads file up until the delim in your case '/'. The delim is extracted and discarded.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  5. How to convert char read from file into string
    By cruxxe in forum C Programming
    Replies: 7
    Last Post: 05-22-2002, 02:09 PM