H'H
H'H

Reputation: 1680

set a timer for array member

Here is the structure of my algorithm in (C):

int window [40];

I am using function below to add member into my window array:

void add_function(int array[], int member);

and delete_function to erase "member" from my window array:

void delete_function(int array[], int member);

I need a function (I do not know how to do it) to check if a member of window array is staying in the array for more than a e.g. 180 sec. (3min).

DO you think that it is possible to define a parallel array (same size of widow array) and initialize it when I add member to the window array (e.g. "regtime") so that I can check the difference between "regtime" and current time.

Any better idea will be appreciated in advance.

Upvotes: 2

Views: 306

Answers (1)

John Odom
John Odom

Reputation: 1213

You would need to have an array of structures kind of like this for example:

struct TIME_STRUCT
{
    int member;
    time_t entryTime;
};

With this you will have to modify your add_function to accommodate the new structure and so that when the array element is added to the array, the current time will be added to entryTime with the use of the time function. Check out this link on how to get the current time:

http://www.cplusplus.com/reference/ctime/time/

Don't forget to modify your delete_function so you can properly delete the new array of structures.

Upvotes: 4

Related Questions