I have a file and I want to read the content of this file line by line with fgets()
. There are 10 lines in this file. Each line should contain amongst other things either the word "day" (occurs 5 times in file) or the word "night" (occurs 5 times in file) (both in lower case).
Each line can also consist of whitespace(s) before or after the word "day" or "night" and also must hold a number (3, 11)
or one of the lower case letters (a,b,c)
per line.
For example:
day 3
night 11
night a
night b
day 11
night c
night 3
day a
day c
day b
My idea is to first check in each line before \n
with strcmp()
if either "day" or "night" occurs. If so then I want to know if there exists either a (3, 11)
or a (a,b,c)
for this "day" or "night". Here my thoughts are the following: What if I delete all whitespaces in each line and determine the number or letter followed by "day" or "night". The problem is that I got stuck here and I do not know what is the best way to determine this. All my thoughts are a way to inconvenient to implement.