The following, from your original post.. should work.
Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>
int
main()
{
size_t size;
int buf;
size = sizeof buf;
sysctlbyname("hw.acpi.battery.life", &buf, &size, NULL, 0);
printf("%d\n", buf);
return 0;
}
Take care pal.
EDIT: Fixed the above code, should work now.