ILE C/C++ Programmer's Guide

Reading Text Stream Files

During a read operation from a text stream file, all the trailing blank characters (hexadecimal value 0x40) in the record that are read from the file into a buffer are ignored. A new-line character is inserted after the last non-blank.

Figure 87. Reading from a Text Stream File


Example:

The following example illustrates how to read from a text stream file.

Figure 88. ILE C Source to Read Characters from a Text Stream File




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

result = fgets ( buf, sizeof(buf), fp );
printf("%10s", result);
result = fgets ( buf+5, sizeof(buf), fp );
printf("%10s", result);

fclose ( fp );
return 0;
}


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