John F John F - 1 month ago 11
C++ Question

Read in a certain line only?

I'm making a program to read in a configuration file and I only want to read certain lines. Example:

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'm using your basic I/O:

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

Answer

You can mark lines you don't want to read with some character or a number, so whenever input stream reads it, you can skip it.

0 This is a test configuration text file 0 It isn't supposed to read this line or the line above it

1 Read this line, but not the white space above or below it

0 Don't read this line or the white space above or below it

0 Read this line, but not the white space above or below it

Then check value in first place of every line and skip it/ read it. Or use something like multiline comments in C /* commented out */ check for opening character and skip everything before closing character.

Comments