Okay, first of all, I'm not too sure what you're trying to accomplish - you said you need to obtain the uid, but getpwuid is for looking up other information based on uid. Did you maybe want getpwnam, which looks up based on username? And then you need to use the uid for another function?
In any case, everything I say below applies to both getpwnam and getpwuid - just swap out the uid argument for the username argument.
You've mixed up your documentation a little bit. An almost-quote from the man page:
struct passwd *getpwuid(uid_t uid);
int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp);
The getpwuid() function returns a pointer to a structure containing the broken-out fields of the record in the password database that matches the user ID uid.
The getpwuid_r() function obtains the same information, but stores the retrieved passwd structure in the space pointed to by pwbuf.
It sounds like you're simply a bit fuzzy on pointers in general. However, you don't have to worry too much for this job it sounds like for your purposes the simpler version might be fine:
struct passwd * my_passwd;
my_passwd = getpwuid(uid);
// or:
// my_passwd = getpwnam(username);
if (my_passwd == NULL) {
// the lookup failed - handle the error!
} else {
// the lookup succeeded - do your thing
printf("User name: %s\n", my_passwd->pw_name);
printf("User password: %s\n", my_passwd->pw_passwd);
...
}
Note that in this case you don't need to allocate memory for the pointer, because getpwuid returns a pointer to the structure with the memory allocated and information stored.
The full definition of the structure (names of other members) is in the man page.
The second form, getpwuid_r, is better for more careful error-handling and memory management, but if all you need to do is a quick lookup, this should be fine.