SD + electrical energy failure

First of all, sorry for my bad English.

I have one question (problem). Maybe someone can help me.

I have make a simple project that the main aim is count how many recyclable object were deposited in a barrel.

The counts are made with the aid of an infrared LED. Data is begin stored (not optimally) in EEPROM. This way if a power supply problem occur, I can recover the data when the system restart.

However, the EEPROM is a limited feature.

I'm not good at programming, so I wonder know if someone can give me a tip.

I need write how many objects are deposited in a barrel, criate an archive on a SD card. In this arquive I need write the complete time and date and the number of the last object deposited. For exemple:

Time - Date - Object number
10:30:32 - 2019/07/25 - 150
10:35:12 - 2019/07/25 -151
08:00:00 - 2019/07/26 -152

The number of objects deposited will be appear in a LCD dispaly.

In case of failalure of power supply I need that the last number recorded on SD card to reappear on the LCD when power is restored (in this case just the number 152 is enough) and the recording (complete) on the SD card to continue where it left off.

I can do this recording the data on a EEPROM, but I don't know how I can do it using a SD card.

Someone can help me with some tip?

Thank you in advance.

You can read the file a line at a time at startup and when you get to the last one, parse the last used number out of that line. Since you're using a fixed width format, you know where the number will be within the line, so you can just pass it's address to atol.

When you open the file for writing, it should be opened in append mode automatically, so any new data you write will appear at the end of the file.

If you don't want to go to the trouble for reading the file, just carry on with your EEPROM method.