UNIX环境高级编程1-3用标准I/O将标准输入复制到标准输出

标准I/O函数getc与putc使用示例
// program 1-3 file/getcputc.c
#include "apue.h"
/*
The standard I/O functions provide a buffered interface to the unbuffered I/O
functions. Using standard I/O relieves us from having to choose optimal buffer sizes,
such as the BUFFSIZE constant in Figure 1.4. The standard I/O functions also simplify
dealing with lines of input (a common occurrence in UNIX applications). The fgets
function, for example, reads an entire line. The read function, in contrast, reads a
specified number of bytes. As we shall see in Section 5.4, the standard I/O library
provides functions that let us control the style of buffering used by the library.
The most common standard I/O function is printf. In programs that call
printf, we will always include <stdio.h> normally by including apue.h as this
header contains the function prototypes for all the standard I/O functions.

The function getc reads one character at a time, and this character is written by putc.
After the last byte of input has been read, getc returns the constant EOF (defined in
<stdio.h>). The standard I/O constants stdin and stdout are also defined in the
<stdio.h> header and refer to the standard input and standard output.
*/
int main()
{
    int c;

    while ((c = getc(stdin)) != EOF)
    {
        if (putc(c, stdout) == EOF)
        {
            err_sys("output error");
        }
    }

    if (ferror(stdin))
    {
        err_sys("input error");
    }

    return 0;
}

 

 

 

 

 

 

 

 

_1N9B@PQ52X@3O08AQC8`K0

 

%WCS$IK{_F_KG2BT{$@RM30

 

 

 

131a68cdb61fceb569b924f006c749f5

 

191594192294199495212911247530344861d9f988f46

398806eb161461828d8bd746b3c8c3ac

4034970a304e251f73481ee5a586c9177f3e5374

转载于:https://www.cnblogs.com/sunyongjie1984/p/4259879.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值