Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 VC7 VC7.1 VC8.0 Visual-Studio , +
Hi all,
I'm currently implementating binary file reading in my mfc project.
cocept work so fine but problem arises for wrong input binary file.
like below
my binary file should contain,
4 bytes of header
10 bytes data like
name varies from 5 to 10 bytes.
 
now when i wrong intput file contain only 5 bytes i got assertion
because i excepted 15 bytes so what is alternative to come out of this error
 
thanks
Posted 15-Dec-11 1:02am
Comments
SAKryukov at 15-Dec-11 8:11am
   
Not a question. What's the problem?
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Coder Block wrote:
now when i wrong intput file contain only 5 bytes i got assertion
because i excepted 15 bytes so what is alternative to come out of this error

The alternative, of course, is checking the file length before actually parsing the
file.
  Permalink  
Comments
Coder Block at 16-Dec-11 3:29am
   
but i dont know the size of binaly file then
CPallini at 16-Dec-11 3:46am
   
Why?
You should define carefully the format of your file and do a preliminary check to avoid the debug assertion.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You have not said what you are using to do the read. Code would be nice, but...
C has _lseek() to do that and CFile has GetLength(). Not knowing the length of a file you are reading is going to cause you problems over and over again. This is a good example of an area that you should program quite defensively. Otherwise, you will have many bugs waiting to get you in your code.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 480
1 Maciej Los 330
2 Richard MacCutchan 225
3 BillWoodruff 185
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,759
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,269
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 15 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100