Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: , +
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
Comments
Sergey Alexandrovich Kryukov 15-Dec-11 8:11am    
Not a question. What's the problem?
--SA

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.
 
Share this answer
 
Comments
Coder Block 16-Dec-11 3:29am    
but i dont know the size of binaly file then
CPallini 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.
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900