当前位置:网站首页>Understanding of C language EOF
Understanding of C language EOF
2022-07-28 06:59:00 【Zhaoyang】
understand
EOF Is the end of the file , Is a macro definition (C All input and output operations in the language are designed according to the idea of reading files )
utilize getchar And putchar Function can detect the input characters , If it is not the end of document indicator ( When reading files , When encountering the end position of the file or error in reading data, it will return EOF) Then copy the character to the output .
#include<stdio.h>
#include<stdlib.h>
int
main()
{
int ch;
int line;
int at_begining;
line =0;
at_begining=1;
/*
* Read characters and process them one by one ;
*/
while( (ch = getchar()) != EOF ){
/*
* If we are at the beginning of a line , Print line number ;
*/
if (at_begining==1){
at_begining = 0;
line += 1;
printf("%d",line);
}
/*
* Print character , And detect the end of the line ;
*/
putchar( ch );
if( ch == '\n')
at_begining = 1;
}
return EXIT_SUCCESS;
}The source code of this case realizes : Read a few lines of input from standard input . Each line of input should be printed on the output , The line number should be added to the front . When writing a program, try to make the input lines processed by the program unlimited .
边栏推荐
- JS四则运算重新封装,解决精度丢失问题
- Technology sharing | how to do Assertion Verification in interface automated testing?
- Software testing (concept)
- Wechat applet custom compilation mode
- cocos2d-x 学习笔记——瓦片地图TiledMap
- CentOS7部署MySQL数据库服务器
- Applets: lifecycle
- Shell script - sort, uniq, TR, array sort, cut, Eval command configuration
- Small tips
- Pku-2739-sum of constructive prime numbers
猜你喜欢

What's a good gift for Tanabata? Niche and advanced product gift recommendation

Technology sharing | sending requests using curl

KVM hot migration

Vmware workstation configuration net mode

修复故障扇区

NFS shared storage service

Centos7 deploy MySQL database server

Qgraphicsview promoted to qchartview

Shell script - "three swordsmen" awk command

FTP服务
随机推荐
Hdu-1159-commonsubsequence (LCS longest common subsequence)
技术分享 | 使用postman发送请求
Technology sharing | do you know the functions of the server interface automated testing and requests library?
技术分享 | 接口测试常用代理工具
QGraphicsView提升为QChartView
防火墙——iptables防火墙(四表五链、防火墙配置方法、匹配规则详解)
TCP/IP五层模型
[learning notes] linked list operation
Technology sharing | sending requests using curl
单元测试框架Jest搭配TypeScript的安装与配置
What's a good gift for Tanabata? Niche and advanced product gift recommendation
[learning notes] knowledge management
Life cycle (process) of software testing
Escape character notes
Forward and backward slash notes
Custom component -- pure data field & component life cycle
搭建PHP7私有仓库
测试人生 | 二线城市年薪超40W?疫情之下涨薪100% + 是怎么做到的?
Hdu-1097-a hard puzzle (fast power)
MySQL主主