In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
The purpose of this article is to share with you the example analysis of the getline function in CCMG +. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
The getline function is a common function. According to its name, we can know that this function is used to read a row of data.
In the standard C language, the getline function does not exist.
Here is a simple implementation:
Int getline_ (char s [], int lim) {int cjingi; iMagi0; while ((c=getchar ())! = EOFOBECTIVE n'&&i0'\ n'&&i0) printf ("% s\ n", s); return 0;}
But there is something wrong with this implementation, which stops even when a blank line is encountered.
In order to solve this problem, we need to reconsider the judgment condition of while cycle.
In the above implementation, we stop when we encounter EOF and newline'\ n', and then judge whether the string we read is greater than 0 or not.
In order to be able to read a blank line, we need to determine whether the ending EOF is being read, and if not, just keep reading.
One more thing, what is EOF?
EOF is used in C language to distinguish between valid data and input Terminator.
The solution adopted by the C language is that when there is no input, the getchar function will return a special value, which is different from any actual character. This value becomes EOF (end of file, end of file). When we declare the variable c, we must make it large enough to hold any value returned by the getchar function. The reason c is not declared as char is that it must be large enough to store the file Terminator EOF in addition to any possible characters.
The input to EOF is locked by the system. Under windows is ctrl+d under ctrl+z,linux/unix.
The following is the modified getline function
Int getline2_ (char s [], int lim) {int cjorii; iMagi0; while ((c=getchar ())!) = EOFTA citation
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.