源代码样本

图 1。 T1520ASP -ILE C 用于处理到达序列中的数据库记录文件的源
/* 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);
} 
注:
  1. 此程序使用 _Ropen() 函数来打开输入文件 T1520ASI ,以按添加记录的顺序访问这些记录。
  2. _Ropen() 函数还会打开输出文件 T1520ASO。
  3. _Rread() 函数读取文件 T1520ASI中的记录。
  4. _Rwrite() 函数将它们写入文件 T1520ASO。