我正在尝试使用 stdio.h 中的 c 库函数 fputc
我假设它应该根据https://linux.die.net/man/3/fputc上的规范工作
具体来说,感兴趣的部分是:
根据这些信息,我假设如果 fputc 成功将字符写入提供的流,我应该收到一个等于写入字符的返回值,如果写入流失败,我应该得到 EOF 的值。
这是我的代码:
// COMPILE
// gcc -Wall -Wextra -Werror -O3 -s ./fputc.c -o ./fputc-test
// RUN
// ./fputc-test
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
void print_error_exit();
int main() {
FILE * fp;
// ensure file exists
if((fp = fopen("file", "w")) == NULL) print_error_exit();
// close stream
if(fclose(fp) == EOF) print_error_exit();
// open file …Run Code Online (Sandbox Code Playgroud)