// crt_read.c
/* This program opens a file named crt_read.txt
* and tries to read 60,000 bytes from
* that file using _read. It then displays the
* actual number of bytes read.
*/
#include <fcntl.h> /* Needed only for _O_RDWR definition */
#include <io.h>
#include <stdlib.h>
#include <stdio.h>
#include <share.h>
char buffer[60000];
int main( void )
{
int fh;
unsigned int nbytes = 60000, bytesread;
/* Open file for input: */
if( _sopen_s( &fh, "crt_read.txt", _O_RDONLY, _SH_DENYNO, 0 ) )
{
perror( "open failed on input file" );
exit( 1 );
}
/* Read in input: */
if( ( bytesread = _read( fh, buffer, nbytes ) ) <= 0 )
perror( "Problem reading file" );
else
printf( "Read %u bytes from file\n", bytesread );
_close( fh );
}