Ok, the problem with the C example was the wrong printf() statement, as anemos pointed out.
The problem with the python example was that I used the wrong type for buf, string instead of int.
For those interested, a working python example:
Code:
import ctypes
libc = ctypes.CDLL('libc.so')
size = ctypes.c_size_t()
buf = ctypes.c_int()
size.value = ctypes.sizeof(buf)
libc.sysctlbyname("hw.acpi.battery.life", ctypes.byref(buf), ctypes.byref(size), None, 0)
print buf.value
However, BSDFan666 pointed out over jabber that the
apm(8) command is a more convenient and portable way of getting the same information ... Thanks!