c - C中putc()的宏实现

标签 c io

我正在寻找 C 中 putc() 函数的宏实现。

我在 Ritchie 和 Kernighan 的“The C programming language”中找到的一个实现

#define putc(x,p) (--(p)->cnt >=0 \
                  ?(unsigned char) *(p)->ptr++ :_flushbuf((x),p))

文件结构定义如下

typedef struct _iobuf {
                int cnt;
                char *ptr;
                char *base;
                int flag;
                int fd;
             }FILE;

当我们调用 putc 时,我看不到 cnt 是如何初始化的?

最佳答案

毫无疑问,它由 fopen 初始化,并由任何其他读取/写入文件的内容修改。

关于c - C中putc()的宏实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9713944/

相关文章:

java - 读取 gz 文件并跟踪文件中的位置

string - 如何在输出的同一行从键盘读取字符串?

c - 使用指针将结构体添加到数组

c - 在 c 中打印形状 x 次

c - seteuid(0) 之后调用 popen 失败

File.read 的 Ruby 性能

j2mepolish 中的 java.io.File 不工作

c - 在 C 中将二维数组引用到函数和逗号分隔语句的其他最佳或更好的方法

c - 值与类型 : Code to Determine if a Variable Is Signed or Not

c - 在 C 代码中写入和读取 long int 值