Char** to char*, possible?

Hello everyone. I am a newish c++ programmer. I currently have a char** which holds a collection of passwords. This char** is created dynamically as i dont know how many passwords my program will have when it starts up. So i have something like this:

[\code]
char ** pwdAry;
pwdAry = new char *[numberOfPasswords];

for (int a = 0; a < numberOfPwd; a++) {
pwdAry[a] = new char[1024];
}
[\code]

I need to be able to convert it to a char* so that i can pass it to a cuda kernel. Is this possible?

Cheers
I need to be able to convert it to a char* so that i can pass it to a cuda kernel. Is this possible?
You have an array of char *.

The type of pwdAry[a] is actually char *.

Please remove the \ in front of the first [\code]
you can convert that like this:
1
2
char** passwords;
char* pass1=(char*) passwords[0];

you can use NumPWDS variable (i think you've named it) to reffer to it but numPWDS -1 is correct
because the array start's indexing at 0
char** is like array, also char* is array of chars
@heepoo

Since passwords[0] is char * the cast is unnecessary:

1
2
3
4
5
char** passwords;
...
// allocate memory for passwords
...
char* pass1=passwords[0]; // Note: no cast 
Topic archived. No new replies allowed.