Fopen, fread, And 1A

Source: Internet
Author: User
// ================================================ ========================================================== ======================================
// Title:
// Fopen, fread, And 1A
// Author:
// Norains
// Date:
// Friday 25-July-2006
// ================================================ ========================================================== ======================================
If fopen is not opened in binary mode, such as fopen (filename, "R"), the fread function stops reading as long as the file contains a byte of 1A. if fopen (filename, "rb") is used, this problem will not occur.
You can use the following code to read any PNG Image for verification. If fopen adopts the "r" method, fread can only read 5 bytes, because the sixth bit of the PNG image is 1A!
The Code is as follows (replace fopen with _ wfopen in EVC ):
Int getreadnum (lpctstr pcszfilename)
{
# Define max_read_num 10

File * PFS;
PFS = _ wfopen (pcszfilename, text ("R"); // PFS = _ wfopen (pcszfilename, text ("rb "));
If (PFS = NULL)
{
Return 0;
}
Int itype = img_nosupport;
Pbyte pbuffer = NULL;
Pbuffer = (pbyte) malloc (sizeof (byte) * max_read_num );
Int ireadnum = fread (pbuffer, sizeof (byte), max_read_num, PFS );
Free (pbuffer );
Return ireadnum;
}
Use this code to read PNG images. The returned value is 5! If fopen is "rb", everything is normal, it is 10!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.