I'm somewhat new to C (and also to this website) and had a question about a project I'm working on. The part I'm stuck on is file I/O stuff, since I never learned that part in my previous class. So, the input (.txt) file looks like this:

```
REGISTERS
R5 11
R7 15
R21 4
MEMORY
4 12
12 92
[OTHER STUFF]

```

The file gives us arbitrary register numbers, followed by its contents (R0 to 31, Regs with value 0 omitted). The next section gives memory locations in a similar format, followed by the contents again. Then more sections that I can deal with later. 

My question is: how do I read in the register/memory locations and their values? Currently I have a size 32 array to store the contents in and a variable for the Reg number and value (Example: Registers[regNumber] = regValue;), but I don't know how to start properly reading values after the word REGISTERS.

What I've tried:

I did some looking around and I managed to read in a test input file with only one line: "R5 11". For this I did:

```
fscanf(file_ptr, "R%d %d", &regNumber, &regValue);

```

I printed the variables regNumber, regValue, and they properly gave me 5 and 11. But how do I do this for any number of lines after the word REGISTERS and stop at the word MEMORY?

I'm assuming whatever the solution is, I can do the same thing to read in the MEMORY locations and values.