I need help with file reading/writing in C

Hello everybody,

I'm trying to code a program which makes the following:

It sends an ARP request frame and when it gets the reply, extracts the IP address of source and writes it to a .txt file. This is gonna be done with many hosts (with a for() loop), so, the text file would look like this:

192.168.1.1
192.168.1.2
192.168.1.3
...

After that loop, the program will construct ARP frames, but it will use as target IP addresses the ones previously written in the .txt file one by frame. I'm okay with sockets, but i need help with the file access.

What i need, is a way to write the addresses in the file from a variable(arp_src_addr, for example), without overwritting previous ones in the file, and once the program is done with receiving frames, a way to read the .txt file and put the first IP of the list into a variable, so i can use that variable to construct a frame with that address, then read again the file and put the second IP address into the variable, then the third, and so on...

Please help me, it's urgent!

This is not encouraged here.

I might have not understood your problem completely, please correct me if am wrong.
From what I have read from the question you have posted,
its dump data read from structure to a file
keep appending the data read from structure again
close the file
open it and read the data structure again ...

For all these you have libraries,
fopen - in append mode
fwrite
fclose
fread

That's not properly help, but thanks anyway.