Skip to main content
gamedev.net
🔒 Locked

Char**

Started by gimp Apr 24, 2004 at 4:23 AM 2 replies 300+ views
Original Post
gimp
gimp
I''m sure this is grossly simple: I''ve never come across char** except when recieved from main(). I''m writing a test case for some code that accepts this data. I can''t figure out how to write some test data for this function. So, how would I create a char** block of data in my code? What does it look like? Many thanks,
Chris Brodie
Jingo
Jingo
Well you are pretty much making an array of pointers to arrays.


void func(char** parray, unsigned int size);

char array[10], array2[10];
char *array3[2];

array3[0]=array;
array3[1]=array2;

func(array3, sizeof(array3)/sizeof(char*));



[edited by - Jingo on April 24, 2004 5:36:31 AM]
gimp
gimp
Thanks Jingo, the compiler liked it:


char* String1 = "Key4=Value4";
char* String2 = "Key5=Value5";
char *Elements[2];
Elements[0]=String1;
Elements[1]=String2;




[edited by - gimp on April 24, 2004 5:37:30 AM]
Chris Brodie
Jingo
Jingo
You should note that char* String1 = "Key4=Value4"; is a deprecated conversion in C++. It should be either of


const char[] string1 = "Key4=Value4";
const char* string2 = "Key4=Value4";
//Elements should be changed to something like

const char* Elements[2];


But using those will no doubt give you problems passing it to the char** function. The function should be changed to accept a char const** parameter.


void func(char const** parray, unsigned int size);

const char array[] = "eg", array2[] = "eg";
char const* array3[2] = {array, array2};
func(array3, sizeof(array3)/sizeof(char*));



[edited by - Jingo on April 24, 2004 5:48:53 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.