Basically, I'm trying to get back a few structs from the results of a few functions called within a function in order to pass those values into something else later. However, I'm not having any luck.
I took out bits of my code for an example and reduced it down to one struct (however, I don't want to use it as the "return value"... as in my whole app I need a single function to return a bunch of structs by pushing them in as parameters that may or may not hold values).
For "simpleTest"... things work as I'd expect. For my "linuxTest"... the results are odd for my struct. I'm missing something stupid... I know it. (For those not familiar with Linux and the Linux function I'm calling... I'm hoping it might be obvious enough just looking at it... maybe... not sure.)
Thanks for any help you can give me!
RESULTS:Code:#include <stdio.h>
#include <pwd.h>
struct testStruct
{
int x;
char *y;
};
void linuxTest( struct passwd *pwdResult )
{
struct passwd pwd;
char pwdBuffer[ 4096 ];
uid_t myUid = 501;
char* uname;
if ( getpwuid_r( myUid, &pwd, pwdBuffer, 4096, &pwdResult ) == 0 &&
pwdResult != NULL )
{
uname = pwdResult->pw_name;
}
else
{
uname = "unknown";
}
printf( "Username: %s\n", uname );
}
void linuxTest()
{
struct passwd pwdResult;
linuxTest( &pwdResult );
printf( "Username: %s\n", pwdResult.pw_name );
}
void simpleTest( struct testStruct *test )
{
test->x = 7;
test->y = "some value";
printf( "TestValue: %s\n", test->y );
}
void simpleTest()
{
struct testStruct test;
simpleTest( &test );
printf( "TestValue: %s\n", test.y );
}
int main()
{
printf( "Starting...\n" );
simpleTest();
linuxTest();
printf( "End.\n" );
return( 0 );
}
Starting...
TestValue: some value
TestValue: some value
Username: dougs
Username: X�����
End.
