JJL
JJL

Reputation: 131

What Regex expression for fscanf() will ignore any character/string/special character in a line?

I am trying to come up with a regex expression that can ignore any character in a line (after I read my relevant input). In a way, its treating the characters after a certain point in the txt file as a comment, but the comment is 'anything' but the relevant information I need. Here's what I have and its worked, but am wondering if there's a more elegant way to handle this:

fscanf(input_file, "%*[a-zA-Z .^$*+?()[{\'\" \t]", temp_char)

temp_char is a char* buffer.

Thanks

Upvotes: 1

Views: 4085

Answers (1)

chqrlie
chqrlie

Reputation: 144951

If you want to consume every character different from \n and the final \n, use these statements:

fscanf(input_file, "%*[^\n]");
fscanf(input_file, "%*c");

The first ignores all characters different from \n, but fails if there are none. The second consumes the \n character.

Upvotes: 3

Related Questions