ILE C/C++ Programmer's Guide

Source Code Sample

Figure 128. T1520ASP -- ILE C Source to Process a Database Record File in Arrival Sequence


/* This program illustrates how to copy records from one file to    */
/* another file, using the _Rreadn(), and _Rwrite() functions.      */
 
#include <stdio.h>
#include <stdlib.h>
#include <recio.h>
 
#define _RCDLEN 300
 
int main(void)
{
    _RFILE   *in;
    _RFILE   *out;
    _RIOFB_T *fb;
    char     record[_RCDLEN];
 
/* Open the input file for processing in arrival sequence.         */(1)
 
    if ( (in = _Ropen("*LIBL/T1520ASI", "rr, arrseq=Y")) == NULL )
    {
        printf("Open failed for input file\n");
        exit(1);
    };
/* Open the output file.                                           */2( 
)    if ( (out = _Ropen("*LIBL/T1520ASO", "wr")) == NULL )
    {
        printf("Open failed for output file\n");
        exit(2);
    };
 
/* Copy the file until the end-of-file condition occurs.           */
 
    fb = _Rreadn(in, record, _RCDLEN, __DFT);(3)
    while ( fb->num_bytes != EOF )
    {
        _Rwrite(out, record, _RCDLEN);(4)
        fb = _Rreadn(in, record, _RCDLEN, __DFT);
    };
 
    _Rclose(in);
    _Rclose(out);
} 

Notes:

  1. This program uses the _Ropen() function to open the input file T1520ASI to access the records in the same order that they are added.

  2. The _Ropen() function also opens the output file T1520ASO.

  3. The _Rread() function reads the records in the file T1520ASI.

  4. The _Rwrite() function writes them to the file T1520ASO.


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