Microsoft KB Archive/49872

{|
 * width="100%"|

fread Can Read More Than 64K at a Time

 * }

Q49872

6.00 6.00a 6.00ax 7.00 | 1.00 1.50 1.51 1.52 MS-DOS | WINDOWS -- The information in this article applies to: - The C Run-time (CRT), included with: - Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax - Microsoft C/C++ for MS-DOS, versions 7.0 - Microsoft Visual C++ for Windows, versions 1.0, 1.51, and 1.52 -- SUMMARY ======= In Microsoft C it is possible to read more than 64K at a time with the fread function by specifying an item size greater than 1 and a count from 1 to 64K. The resulting number of bytes read will be the product of size and count. MORE INFORMATION ================ The follow code demonstrates how to read a file 200K in length: Sample Code --- /* Compile options needed: /AL */ #include char huge buffer[205000]; void main(void) { FILE *fp; fp=fopen(&quot;testfile.dat&quot;,&quot;r&quot;); fread(buffer,4,51200,fp); /* 51200*4=204,800 */ /* The value returned from the line above will be the number of items read. This number is limited to 64K because it is of type size_t. But remember, the total number of bytes read is equal to the number of items times the size of each item, which is 4 bytes in this case. Therefore, the total bytes read is 4 times 51200 or 204,800 bytes. */ } Additional reference words: kbinf 1.00 1.50 1.51 1.52 5.10 6.00 6.00a 6.00ax 7.00 KBCategory: KBSubcategory: CRTIss

Keywords : kbcode kb16bitonly kbCRT kbVC

Issue type :

Technology : kbVCsearch kbAudDeveloper kbCRT