Sign in to follow this  
Xhadow

Problem whit pointers and functions

Recommended Posts

Hello, i have a little problem ok first le me show the code void FunctionX( char **szOut ) { char sztemp[128]; strcpy( sztemp, "Hello" ); strcpy( szOut[0], sztemp ); strcpy( szOut[1], sztemp ); strcpy( szOut[2], sztemp ); } void OMG( void ) { char szOut[10][128]; FunctionX( &*szOut ); // I dont know how to call it properly vShowText( szOut[0] ); vShowText( szOut[1] ); vShowText( szOut[2] ); } I got an error i tryed to call like &*szOut since i dont know how to use long pointers properly i need some lessons hehe... sooo... how to do it?

Share this post


Link to post
Share on other sites
Like FunctionX( &*szOut ); Error:
cannot convert parameter 1 from 'char[*][128]' to 'char **'

Like FunctionX( **szOut ); Error:
cannot convert parameter 1 from 'char' to 'char **'

Share this post


Link to post
Share on other sites
The bottom of this problem is that arrays are not pointers. Therefore, an array of pointers is not the same as an array of arrays, and the compiler is perfectly correct in complaining.

Correct it either by changing the function prototype to void FunctionX( char (*szOut)[128] ), or make szOut an array of pointers instead of an array of arrays. First option means you can only pass an array of arrays whose length are 128, and second option means you must dynamically allocate memory for it.

Share this post


Link to post
Share on other sites
void OMG( void )
{
char szOut_storage[10][128];
char* szOut[10];

for(size_t i=0; i<10; i++)
szOut[i] = szOut_storage[i];

FunctionX(szOut);

vShowText( szOut[0] );
vShowText( szOut[1] );
vShowText( szOut[2] );
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this