• Advertisement
Sign in to follow this  

Problem whit pointers and functions

This topic is 3571 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
You haven't considered.... perhaps telling us what error you get? That'd make it quite a lot easier to tell you what is wrong.

Share this post


Link to post
Share on other sites
ok like FunctionX( szOut ) the error is:
cannot convert parameter 1 from 'char[10][128]' to 'char **'

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 = szOut_storage;

    FunctionX(szOut);

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

    Share this post


    Link to post
    Share on other sites
    Sign in to follow this  

    • Advertisement