When you read a file than your file pointer is at the end of the file. You need to
rewind or fseek to read the file.
By the way: a
fgets would make your code easier to understand and faste.
Use the debugger to find out what is going on in your code.
Bonus-tip: Wrap your loops in functions.