ILE C/C++ Programmer's Guide

Writing Text Stream Files

During a write operation, a new-line character in the buffer causes the remainder of the record written to the text stream file to be padded with blank characters (hexadecimal value 0x40). The new-line character itself is discarded.

Figure 85. Writing to a Text Stream File


If the number of characters being written in the buffer exceeds the record length of the file, the data written to the file is truncated, and errno is set to ETRUNC.

Example:

The following example illustrates how to write to a text stream file.

Figure 86. ILE C Source to Write Characters to a Text Stream File




#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char buf[12] = "abcd\nefghi\n";
FILE *fp;
/* Open a text file for writing. */
if (( fp = fopen ( "MYLIB/TEST(MBR)", "w" ) ) == NULL )
{
printf ( "Cannot open file\n" );
exit ( 1 );
}
/* Write characters to the file. */

fputs ( buf, fp );

/* Close the text file. */

fclose ( fp );
return 0;
}


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