c - read() 的输出没有合并到 getchar 中

标签 c getchar kernighan-and-ritchie

几个小时前我问过一个关于这段代码的理论方面的问题。现在我明白了一切,但是,该代码根本没有输出。 这是 http://ideone.com/LWMC5 上代码的链接

代码:

#include <stdio.h>
#include <unistd.h> /* changed from "syscalls.h" it was not working */
/* changed the name intentionally */
int main(void)
{

    static char buf[BUFSIZ];
    static char *bufp = buf; 
    static int n = 0;
    if (n == 0) {            /* buffer is empty */
        n = read(0, buf, sizeof buf);
        bufp = buf;          
    }
    return (--n >= 0) ? (unsigned char) *bufp++ : EOF; 
}

我应该做什么/添加什么来产生输出?

最佳答案

我不明白你期望的输出是什么,要在屏幕上打印一些东西,你需要使用类似 printf 的东西。

关于c - read() 的输出没有合并到 getchar 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12021014/

相关文章:

c - HPUX atof 不会将字符串转换为 double

c - 段错误——无法理解错误的原因

c - getchar 是否定义为宏?

c - 为什么我应该在 C 代码中像这样使用 getchar() ?

c - (K&R) 内部名称至少前 31 个字符是重要的?

c - 带有 EOF 的 getchar() 未按预期运行

c++ - 未定义对 `u_fopen_48' 的引用

C - 从大字符串中的标准输入一次读取一个字符

c - C getchar输入问题

c - K&R 练习 1.21