当前位置:网站首页>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 reverse question 100 - question 1
- Hdu-1159-commonsubsequence (LCS longest common subsequence)
- 防火墙——iptables防火墙(四表五链、防火墙配置方法、匹配规则详解)
- NFS shared storage service
- DHCP principle and configuration
- 链表中结点的插入和删除
- HDU-1159-CommonSubsequence(LCS最长公共子序列)
- cocos2d-x 学习笔记——瓦片地图TiledMap
- HDU-5783 Divide the Sequence(贪心水题)
猜你喜欢

Custom components -- styles

1、 PXE overview and installation

QGraphicsView提升为QChartView

Installation and configuration of unit test framework jest with typescript

SSH service configuration

修复故障扇区

raid磁盘阵列

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

技术分享 | 接口测试常用代理工具

It is recommended to wear air conduction earphones, which do not need to wear in ear
随机推荐
C language memcpy library functions and the role of memmove
Detailed explanation of LNMP construction process
JS four operations are repackaged to solve the problem of precision loss
测试人生 | 二线城市年薪超40W?疫情之下涨薪100% + 是怎么做到的?
Which is the best one to make air conduction headphones? Inventory of the best air conduction headphones
PKU-2524-Ubiquitous Religions(并查集模板)
My deployment notes
Technology sharing | how to simulate real use scenarios? Mock technology to help you
Shell script - sort, uniq, TR, array sort, cut, Eval command configuration
Cocos2d-x learning notes Tile Map tiledmap
Build php7 private warehouse
Tcp/ip five layer model
Wechat applet custom compilation mode
FTP service
Pku-2524-ubiquitous relations (parallel search template)
技术分享 | 实战详解接口测试请求方式Get、post
Qgraphicsview promoted to qchartview
Traversal binary tree
Vmware workstation configuration net mode
测试面试题集锦(二)| 测试工具篇(附答案)