Premature EOF

This is a discussion on Premature EOF within the C Programming forums, part of the General Programming Boards category; Hi guys, I have some code which needs to transfer binary files to a remote server. My problem is, as ...

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

    Question Premature EOF

    Hi guys,

    I have some code which needs to transfer binary files to a remote server. My problem is, as I read the file from my local machine as I perform the transfer, I get a premature EOF so only a small part of the file is actually transferred.

    My loop is as follows:
    Code:
    while ((c = fgetc(fs)) != EOF) {
    I checked the last few bytes that I transfer and they are 00 FF. Could the FF be being interprested as EOF? If so, if there a way around this?

    Thanks for any help!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That depends. Is c a char, or an int? Because you can't test for EOF with a char. Well, you can, but then you run into the problem you're having.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    3
    C is a char. If I made it an int and cast it as a char later would it work?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    One way to find out...

    You'll need to use an integer if you're trying to read until EOF. You'll notice if you look at the man pages or what not, that fgetc actually returns an int. There's a reason for that, which you've just discovered.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Apr 2004
    Posts
    3
    Heheh thanks quzah, doing that works great

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. EOF Explanation Anybody?
    By blackcell in forum C Programming
    Replies: 1
    Last Post: 01-29-2008, 08:09 PM
  2. EOF or not EOF?
    By CornedBee in forum Linux Programming
    Replies: 2
    Last Post: 09-14-2007, 02:25 PM
  3. EOF messing up my input stream?
    By Decrypt in forum C++ Programming
    Replies: 4
    Last Post: 09-30-2005, 03:00 PM
  4. whats the deal with EOF really ???
    By gemini_shooter in forum C Programming
    Replies: 7
    Last Post: 03-06-2005, 03:04 PM
  5. files won't stop being read!!!
    By jverkoey in forum C++ Programming
    Replies: 15
    Last Post: 04-10-2003, 05:28 AM

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