如何读取txt文件中存在多少行? [英] How can I read how many lines exist in a txt file?
本文介绍了如何读取txt文件中存在多少行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在C中编写代码以检入我的文件只包含3行文字?
例如
9820 sads
88182c 9 298 2
88812cec 9 2 88 828
如果在我的txt文件中写入少于或多于3行的名为test.txt,则程序将返回错误消息并退出。
解决方案
参考:
1. c检索文件中的总行数 [ ^ ]
2.使用
退出(0)
退出程序,需要包含
#include< stdlib .H>
How can I write a code in C to check in my file contains only 3 lines of text?
Eg
9820 sads
88182c 9 298 2
88812cec 9 2 88 828
If there are less or more than 3 lines writen in my txt file called test.txt then the program will return an error message and will exit.
解决方案
Refer:
1. c retrieving total line numbers in a file[^]
2. use
exit(0)
to exit a program, need to include
#include <stdlib.h>
这篇关于如何读取txt文件中存在多少行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文