Get the list of logged in users

How can I get the list of logged in users in the system programmatically?
I can get the list with 'who' or 'users' commands but I need to get the list programmatically...
May someone help, please?

Thanks in advance.

Doing it without using who would be difficult. Just capture the output of who. Exactly how to do that would depend on what language you're using.

man utmp will explain how 'who' gets the list of logged on users from the utmp file.