ILE C/C++ Programmer's Guide

Writing Binary Stream Files (character at a time)

If you write data to a binary stream processed one character at a time, and the size of the data is greater than the current record length, then the excess data is written to the current record up to its record size and the remaining data is written to the next record in the file.

Figure 90. Writing to a Binary Stream File One Character at a Time


Example:

The following example illustrates how to write to a binary stream by character.

Figure 91. ILE C Source to Write Characters to a Binary Stream File




#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fp;
char buf[5] = {'a', 'b', 'c', 'd', 'e'};
/* Open an existing binary file for writing. */
if (( fp = fopen ( "MYLIB/TEST(MBR)", "wb" ) ) == NULL )
{
printf ( "Cannot open file\n" );
exit ( 1 );
}
/* Write 5 characters from the buffer to the file. */

fwrite ( buf, 1, sizeof(buf), fp );

fclose ( fp );
return 0;
}


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