打印机文件的记录功能

使用以下记录功能来处理打印机文件:
  • _Rclose()
  • _Rfeod()
  • _Rformat()
  • _Rindara()
  • _Riofbk()
  • _Ropen()
  • _Ropnfbk()
  • _Rupfb()
  • _Rwrite()

示例:

以下示例在程序描述的打印机文件中使用 "第一字符打印纸控制"。 员工的姓名和序列号从物理文件中读取并写入打印机文件。
  1. 要创建打印机文件 T1520FCP,请输入:
    CRTPRTF FILE(MYLIB/T1520FCP) CTLCHAR(*FCFC) CHLVAL((1 (13)))
  2. 要创建物理文件 T1520FCI,请输入:
    CRTPF FILE(MYLIB/T1520FCI) RCDLEN(30)
  3. 在 T1520FCI: 中输入名称和序列号,如下所示:
    Jim Roberts          1234567890
    Karen Smith          2314563567
    John Doe             5646357324
  4. 要使用下面显示的源创建程序 T1520FCF ,请输入:
    CRTBNDC PGM(MYLIB/T1520FCF) SRCFILE(QCPPLE/QACSRC)
    图 1。 T1520FCF -ILE C Source to Use First Character Forms Control
    /* This program illustrates how to use a printer stream file, the   */
    /* _fwrite() function and the first character forms control.        */ 
    #include <stdio.h>
    #include <string.h>
    #define  BUF_SIZE   53
    #define  BUF_OFFSET 20
    
    int main(void)
    {
        FILE        *dbf;
        FILE        *prtf;
        char buf    [BUF_SIZE];
        char tmpbuf [BUF_SIZE];
     
    /* Open the printer file using the first character forms control.     */
    /* recfm and lrecl are required.                                      */ 
        prtf = fopen ("*LIBL/T1520FCP", "wb type=record recfm=fa lrecl=53" );
        dbf  = fopen ("*LIBL/T1520FCI",  "rb type=record blksize=0" );
     
    /* Print out the header information.                                  */ 
        memset ( buf, ' ', BUF_SIZE );
     
    /* Use channel value 1.                                               */ 
        strncpy ( buf, "1                         EMPLOYEE INFORMATION",47 );
        fwrite ( buf, 1, BUF_SIZE, prtf );
    
    /* Use single spacing.                                                */ 
        strncpy ( buf,"                          --------------------",47 );
        fwrite ( buf, 1, BUF_SIZE, prtf );
    /* Use triple spacing.                                                */ 
        strncpy ( buf,"-                   NAME                SERIAL NUMBER"
                 ,BUF_SIZE );
        fwrite ( buf, 1, BUF_SIZE, prtf ); 
        strncpy ( buf,"                    ----                -------------"
                 ,BUF_SIZE );
        fwrite ( buf, 1, BUF_SIZE, prtf );
    /* Print out the employee information.                                */ 
        while ( fread ( tmpbuf, 1, BUF_SIZE, dbf ))
        {
          memset ( buf, ' ', BUF_SIZE );
     
    /* Use double spacing.                                                */ 
          buf[0] = '0';
          strncpy ( buf + BUF_OFFSET, tmpbuf, strlen(tmpbuf) );
          fwrite ( buf, 1, BUF_SIZE, prtf );
        } 
        fclose ( prtf );
        fclose ( dbf );
    }

    fopen() 函数在一次处理时使用记录打开打印机流文件 T1520FCP 。 fopen() 函数还会在一次处理时打开记录的物理文件 T1520FCI 。 strncpy() 函数将记录复制到打印缓冲区中。 fwrite() 函数将打印出员工记录。

  5. 要运行程序 T1520FCF,请输入:
    CALL PGM(MYLIB/T1520FCF)
    输出文件如下所示:
    
                             EMPLOYEE INFORMATION
                             --------------------
                       NAME                SERIAL NUMBER
                       ----                -------------
                       Jim Roberts         1234567890
                       Karen Smith         2314563567
                       John Doe            5646357324
    打印的输出文件如下:
    
                             EMPLOYEE INFORMATION
                             --------------------
    
    
                       NAME                SERIAL NUMBER
                       ----                -------------
    
                       Jim Roberts         1234567890
    
                       Karen Smith         2314563567
    
                       John Doe            5646357324