I have a character array containing my user ID. I need to get a uid_t object so I can look up the username using getpwuid(3).
My command is ./foo 1000
(a user with the name 'bar' and the ID 1000 exists on the system). Here's my code:
int main(int argc, char **argv) {
struct passwd *user = getpwuid((int) argv[1]);
printf("%s\n", user->pw_name);
}
The problem with this is, getpwuid(3) only accepts uid_t, and the (int) casting is not working.
I am well aware that I could use getpwnam() and get it from a string, but I can't figure out how to convert my char array to a uid_t so getpwuid(3) accepts it.