This all depends on the format and resolution the timestamp needs to be in, as pointed out in comments.
To construct a general approach, looking at the date and time utilities of C is useful. If this does not fit your requirements, then you'd have to look for a third party library. Either way, the basic structure of your program will most likely be the same.
Here is a basic example in C11 (with the exception of the sleep function). It prints the structs, sets the timestamps and sleeps. Afterwards it prints the stored timestamps.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define ARRAY_SIZE 20
#define STRUCT_STRING_SIZE 65
struct St
{
time_t timestamp;
char aps[STRUCT_STRING_SIZE];
};
void nanosleepWrapper(void);
time_t timeWrapper(void);
int main(void)
{
struct St arr[ARRAY_SIZE];
// Fill structs array with placeholder data
for (size_t idx = 0U; idx < ARRAY_SIZE; ++idx)
snprintf(arr[idx].aps, STRUCT_STRING_SIZE, "Placeholder value %zu", idx);
// Loop: print struct data, set timestamp, and sleep
for (size_t idx = 0U; idx < ARRAY_SIZE; ++idx)
{
printf("%s\n", arr[idx].aps);
fflush(stdout);
nanosleepWrapper();
arr[idx].timestamp = timeWrapper();
}
// Print all timestamps
for (size_t idx = 0U; idx < ARRAY_SIZE; ++idx)
printf("%zu: %s", idx, asctime(gmtime(&arr[idx].timestamp)));
}
// Sleep using a function which is not standard C, but is POSIX
void nanosleepWrapper(void)
{
struct timespec req = {0, 500000000};
if (nanosleep(&req, NULL) == -1)
fprintf(stderr, "Sleep failed\n");
}
time_t timeWrapper(void)
{
time_t tmp = time(NULL);
if (tmp == (time_t)(-1))
{
fprintf(stderr, "Setting timestamp failed\n");
exit(EXIT_FAILURE);
}
return tmp;
}
Example output:
Placeholder value 0
Placeholder value 1
Placeholder value 2
...
Placeholder value 18
Placeholder value 19
0: Wed Sep 1 11:18:04 2021
1: Wed Sep 1 11:18:05 2021
2: Wed Sep 1 11:18:05 2021
...
18: Wed Sep 1 11:18:13 2021
19: Wed Sep 1 11:18:14 2021