ILE C/C++ Programmer's Guide

Reading Binary Stream Files (character at a time)

During a read operation from a binary stream that is processed a character at a time, if the length of the data being read is greater than the record length of the file, then data is read from the next record in the file.

Figure 92. Reading from a Binary Stream File One Character at a Time


Example:

The following illustrates how to read from a binary stream file by character.

Figure 93. ILE C Source to Read Characters from a Binary Stream File




#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fp;
char buf[6];
/* Open an existing binary file for reading. */
if (( fp = fopen ( "MYLIB/TEST(MBR)", "rb" ) ) == NULL )
{
printf ( "Cannot open file\n" );
exit ( 1 );
}
/* Read characters from the file to the buffer. */

fread ( buf, 1, sizeof(buf), fp );
printf ( "%6s\n", buf );

fclose ( fp );
return 0;
}


[ Top of Page | Previous Page | Next Page | Table of Contents ]