This information is provided through the /proc
filesystem API. Specifically, /proc/uptime
. In C, just open it as a normal file and read one floating point number from it. It will be the amount of seconds since power on. If you read another FP value, it will be how many seconds the system has spent in total being idle. You're only interested in the first number though.
Example:
float uptime;
FILE* proc_uptime_file = fopen("/proc/uptime", "r");
fscanf(proc_uptime_file, "%f", &uptime);
This value is in seconds, floating point.
You can convert it back to clock ticks:
uptime * sysconfig(_SC_CLK_TCK);