Click here to Skip to main content
16,004,944 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: passing array of pointers Pin
Christian Graus15-Nov-06 19:12
protectorChristian Graus15-Nov-06 19:12 
GeneralRe: passing array of pointers Pin
thathvamsi15-Nov-06 20:06
thathvamsi15-Nov-06 20:06 
GeneralRe: passing array of pointers Pin
Christian Graus15-Nov-06 20:10
protectorChristian Graus15-Nov-06 20:10 
GeneralRe: passing array of pointers Pin
thathvamsi15-Nov-06 21:45
thathvamsi15-Nov-06 21:45 
GeneralRe: passing array of pointers Pin
Christian Graus15-Nov-06 21:56
protectorChristian Graus15-Nov-06 21:56 
GeneralRe: passing array of pointers Pin
thathvamsi15-Nov-06 22:12
thathvamsi15-Nov-06 22:12 
GeneralRe: passing array of pointers Pin
Christian Graus15-Nov-06 22:30
protectorChristian Graus15-Nov-06 22:30 
GeneralRe: passing array of pointers Pin
Christian Graus15-Nov-06 22:35
protectorChristian Graus15-Nov-06 22:35 
This actually works just fine.  Obviously, all funcB does is free the names, but they are correctly being passed through.

#include <string.h>
#include <malloc.h>

void funcB(const char ** names)
{
//the actual values names[0] and names[1] are to be accessed and used but they are null!!!???

   
//free names[0] and names[1]
free( (char*)names[0]);
free( (char*)names[1]);

}


void funcA()
{
int array = 4;
char ** Names = new char *[array];
int next = 0;
int i;

//initialise
for(i=0;i < array; ++ i)
{
    Names[i]=NULL;
}

char * list = "Abc";
Names[ next ] = (char*) malloc( sizeof( char )*( strlen( list ) + 1 ) );
memcpy( Names[ next ],list,sizeof( char )*( strlen( list ) + 1 ) );

++next;

list = "cdefg";
Names[ next ] = (char*) malloc( sizeof( char )*( strlen( list ) + 1 ) );
memcpy( Names[ next ],list,sizeof( char )*( strlen( list ) + 1 ) );

printf("vsp list got is %s\n", Names[0] );
printf("vsp list got is %s\n", Names[1] );

funcB((const char**)Names);
}


int main(int argc, char* argv[])
{
    printf("Hello World!\n");
    funcA();
    return 0;
}




Christian Graus - C++ MVP

GeneralRe: passing array of pointers Pin
thathvamsi15-Nov-06 23:08
thathvamsi15-Nov-06 23:08 
GeneralRe: passing array of pointers Pin
Christian Graus15-Nov-06 23:11
protectorChristian Graus15-Nov-06 23:11 
GeneralRe: passing array of pointers Pin
Christian Graus15-Nov-06 23:09
protectorChristian Graus15-Nov-06 23:09 
GeneralRe: passing array of pointers Pin
thathvamsi15-Nov-06 23:19
thathvamsi15-Nov-06 23:19 
GeneralRe: passing array of pointers Pin
Christian Graus15-Nov-06 23:22
protectorChristian Graus15-Nov-06 23:22 
GeneralRe: passing array of pointers Pin
Christian Graus15-Nov-06 23:23
protectorChristian Graus15-Nov-06 23:23 
GeneralRe: passing array of pointers Pin
thathvamsi15-Nov-06 23:33
thathvamsi15-Nov-06 23:33 
AnswerRe: passing array of pointers Pin
Raj Prathap15-Nov-06 18:47
Raj Prathap15-Nov-06 18:47 
GeneralRe: passing array of pointers Pin
thathvamsi15-Nov-06 18:53
thathvamsi15-Nov-06 18:53 
GeneralRe: passing array of pointers Pin
Raj Prathap15-Nov-06 20:47
Raj Prathap15-Nov-06 20:47 
QuestionFrustrated with conversion Pin
Stick^15-Nov-06 15:14
Stick^15-Nov-06 15:14 
AnswerRe: Frustrated with conversion Pin
Christian Graus15-Nov-06 15:24
protectorChristian Graus15-Nov-06 15:24 
GeneralRe: Frustrated with conversion Pin
Stick^15-Nov-06 16:02
Stick^15-Nov-06 16:02 
GeneralRe: Frustrated with conversion Pin
PJ Arends15-Nov-06 16:14
professionalPJ Arends15-Nov-06 16:14 
GeneralRe: Frustrated with conversion Pin
Christian Graus15-Nov-06 16:44
protectorChristian Graus15-Nov-06 16:44 
AnswerRe: Frustrated with conversion Pin
Raj Prathap15-Nov-06 18:51
Raj Prathap15-Nov-06 18:51 
GeneralRe: Frustrated with conversion Pin
Christian Graus15-Nov-06 19:13
protectorChristian Graus15-Nov-06 19:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.