读取未知行数
我需要用 C 语言实现该程序,该程序从标准输入读取未知数量的行。 我知道最大行数是100。 我尝试使用 gets
,但我不知道何时停止循环。 你能告诉我如何实施吗?
I need to implement in C the program ,which reads an unknown number of lines from stdin.
I know that the maximum number of lines is 100.
I tried to use gets
,but I don`t know when to stop the loop.
Can you advise me how to implement it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您希望程序何时停止。有几种常见的方法:
^C
或使用操作系统的功能终止程序QUIT
、EXIT
等单独一行Enter
)为止在你的情况下是100,你可以用它作为限制一旦达到最大值,自动终止输入。
This depends on when you want your program to stop. There are several common approaches:
^C
or otherwise terminates your program using the facilities of your operating systemQUIT
,EXIT
, etc. on a line by itselfEnter
)Since the max number in your case is 100, you can use it as the limit to automatically terminate the input once the max is reached.