只读某一行

Read in a certain line only?

本文关键字:一行 只读      更新时间:2023-10-16

我正在制作一个程序来读取配置文件,我只想读取某些行。例子:

config.txt:

This is a test configuration text file
It isn't supposed to read this line or the line above it
Read this line, but not the white space above or below it
Don't read this line or the white space above or below it
Read this line, but not the white space above or below it

我正在使用您的基本I/O:

FILE *File;
File = fopen("config.txt", "r");

你可以用一些字符或数字标记你不想读的行,所以当输入流读取它时,你可以跳过它。

0这是一个测试配置文本文件0不应该读取这一行或它上面的行

1读这一行,但不读它上面或下面的空白

0不要读这一行或它上面或下面的空白

0读这一行,但不读它上面或下面的空白

然后检查每一行的第一个位置的值并跳过它/读取它。或者使用类似C中的多行注释/*注释掉*/检查开始字符并跳过结束字符之前的所有内容。