Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 14th, 2005, 2:10 PM   #1
galapogos
Newbie
 
Join Date: Feb 2005
Posts: 4
Rep Power: 0 galapogos is on a distinguished road
fread question

Hi,
I'm trying to read from a binary file in blocks of constant size(say 512B), and then write it into another file, with fread() and fwrite(). However, if the original filesize is a multiple of 512, I'm always reading an extra block, and if it's not a multiple of 512, my final block will contain partial data, which will then be written to an output file that is a multiple of 512.

I'm doing a while (0 == feof(file)) and within that loop, a fread(&buffer, 512,1,file). How do I eliminate the final block problem? I'm guessing I'll have to find out the size of the data within the blocks and check if it's <512, but I'm not sure how to do that.
galapogos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:56 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC