Q:

get the current time in seconds

I am wondering is there any function that would return the current time in seconds, just 2 digits of seconds? I'm using gcc 4.4.2.

A:

The following complete program shows you how to access the seconds value:
#include <stdio.h>
#include <time.h>

int main (int argc, char *argv[]) {
    time_t now;
    struct tm *tm;

    now = time(0);
    if ((tm = localtime (&now)) == NULL) {
        printf ("Error extracting time stuff\n");
        return 1;
    }

    printf ("%04d-%02d-%02d %02d:%02d:%02d\n",
        tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
        tm->tm_hour, tm->tm_min, tm->tm_sec);

    return 0;
}

It outputs:
2010-02-11 15:58:29

How it works is as follows.

it calls time() to get the best approximation to the current time (usually number of seconds since the epoch but that's not actually mandated by the standard).
it then calls localtime() to convert that to a structure which contains the individual date and time fields, among other things.
at that point, you can just de-reference the structure to get the fields you're interested in (tm_sec in your case but I've shown a few of them).

Keep in mind you can also use gmtime() instead of localtime() if you want Greenwich time, or UTC for those too young to remember :-).

