C++ Reference: Standard C++ Library reference: C Library: cstdio: fgetc
C++官网参考链接:https://cplusplus.com/reference/cstdio/fgetc/
函数
<cstdio>
fgetc
int fgetc ( FILE * stream );
从流中获取字符
返回指定stream的内部文件位置指示符当前所指向的字符。然后将内部文件位置指示符向前移动到下一个字符。
如果调用时stream位于文件结束处,则函数返回EOF并为stream设置文件结束指示符(feof)。
如果发生读错误,该函数返回EOF并为stream设置错误指示符(ferror)。
fgetc和getc是等价的,除了getc可能在某些库中作为宏实现。
形参
stream
指向标识输入流的FILE对象的指针。
返回值
如果成功,则返回已读取的字符(提升为int值)。
返回类型是int,以适应特殊值EOF,这表示失败:
如果位置指示符位于文件结束,该函数返回EOF并设置stream的文件结束指示符(feof)。
如果发生其他读错误,该函数也返回EOF,但设置其错误指示符(ferror)。
用例
/* fgetc example: money counter */
#include <stdio.h>
int main ()
{
FILE * pFile;
int c;
int n = 0;
pFile=fopen ("myfile.txt","r");
if (pFile==NULL) perror ("Error opening file");
else
{
do {
c = fgetc (pFile);
if (c == '$') n++;
} while (c != EOF);
fclose (pFile);
printf ("The file contains %d dollar sign characters ($).\n",n);
}
return 0;
}
这个程序逐字符读取一个名为myfile.txt的现有文件,并使用n变量计算文件包含多少美元字符($)。
myfile.txt文件存在的情况下的输出:
myfile.txt文件不存在的情况下的输出:
C++ Reference: Standard C++ Library reference: C Library: cstdio: fgetc相关推荐
- Conditional project or library reference in Visual Studio
Conditional project or library reference in Visual Studio In case you were wondering why you haven't ...
- link library 、target library、symbol library、synthetic library对照分析-基础小知识(九)
文章目录 1.1 概念介绍 1.2 疑问解析 参考文档 DC 应用过程中涉及link library .target library.symbol library.synthetic library, ...
- undefined reference to `__stack_chk_guard' .. undefined reference to `__stack_chk_fail'
1. 编译出错 undefined reference to `__stack_chk_guard' undefined reference to `__stack_chk_fail' 解决方法-1: ...
- git fatal: cannot lock ref ‘HEAD‘:unable to resolve reference‘refs/heads/main‘:reference broken
问题: push的时候,电脑强制关机再启动,vscode中所有文件都变成了绿色,暂存待提交状态 当我再次提交时,就出现错误:git fatal: cannot lock ref 'HEAD':unab ...
- undefined reference to 'floor'/undefined reference to
undefined reference to 'floor'/undefined reference to `& undefined reference to 'pow'/undefined ...
- 问题排查--@cannot lock ref 'HEAD': unable to resolve reference 'refs/heads/master': reference broken解决方法
@cannot lock ref 'HEAD': unable to resolve reference 'refs/heads/master': reference broken解决 作者用的是ID ...
- C++ Reference: Standard C++ Library reference: C Library: cmath: cbrt
C++官网参考链接:https://cplusplus.com/reference/cmath/cbrt/ 函数 <cmath> <ctgmath> cbrt C99 dou ...
- C++ Reference: Standard C++ Library reference: C Library: cmath: erf
C++官网参考链接:https://cplusplus.com/reference/cmath/erf/ 函数 <cmath> <ctgmath> erf C99 doubl ...
- C++ Reference: Standard C++ Library reference: C Library: cstdio: printf
C++官网参考链接:https://cplusplus.com/reference/cstdio/printf/ 函数 <cstdio> printf int printf ( cons ...
最新文章
- 幸运数字Ⅱ(树型结构构造答案,打表)难度⭐⭐
- 这套“人造肌腱”装备,可保护你的老腰|Science子刊
- javascript转换金额格式
- 【翻译】Apache Hbase新特性--MOB支持(一)
- 【LeetCode】2.两数相加
- html网页大小自动调整大小,根据电脑屏幕分辩率大小自动调整网页宽度
- 【Breadth-first Search 】专题3
- mysql数据库 day01
- grafana默认用户名密码_提升运维格调?Grafana整合Zabbix
- linux java部署tomcat_Linux 使用脚本安装Tomcat并部署程序
- 滴滴自研分布式NoSQL数据库Fusion的演进之路
- .net reactor 学习系列(四)---.net reactor应用场景
- docker命令的使用
- lammps教程:磨屑原子Ovito后处理教程
- 设计一个立方体类(长方体)Box,它能计算并输出立方体的体积和表面积。
- python从入门到入土图片_python学习手册-爬爬那些年咱没见过的校花图片
- cubieboard服务器系统,cubieboard 搭建家用服务器
- 软件测试管理--第二章 2.2节
- ExecuteNoQuery()返回值
- 卡尔曼滤波数据融合算法