user13718692
user13718692

Reputation:

Find first occurrence of character in file in C?

This can be done in a string, with strrchr(), but what about finding the first occurrence of a string in a file? So I can know how much to read from the file? Is there a direct way to do that, or will I just have to get all the contents of the file as a string and then use strrchr()?

Upvotes: 0

Views: 384

Answers (1)

Brecht Sanders
Brecht Sanders

Reputation: 7287

You need to read the file contents and use strrchr() on the data you read.

But you don't have to read the whole file at once. You can read chunk by chunk and scan each chunk with strrchr() until you found the character.

Upvotes: 1

Related Questions