c++ - cannot convert char (*)[1000] to char ** -


i created char variable called str , trying pass function. keep on getting error cannot convert char (*)[1000] char **. know cannot convert char char * use & in front of char, cannot figure out in case. searched stack , google , have had no luck. ideas?

 char str2[1000];            strcpy(str2, "/home/" );        strcat(str2, pw->pw_name );         strcat(str2, "/documents/test4.txt" );       char buftest[512];     int link = getsymboliclinktarget(&str2, buftest, sizeof(buftest)); 

here function

int getsymboliclinktarget(char *argv[], char *buf, size_t buf_size){     int count = readlink(argv[1], buf, buf_size);     if (count >= 0) {         buf[count] = '\0';     }     return count; } 

the main problem type of first argument of getsymboliclinktarget char* [] -- array of pointers char.

the type of &str char (*)[1000] -- pointer array of 1000 char.

that's mismatch compiler telling about.

you can solve using various ways:

option 1

change type of first argument of getsymboliclinktarget.

int getsymboliclinktarget(char *argv, char *buf, size_t buf_size){ 

this require changes how use argv in function.

then, can use:

getsymboliclinktarget(str2, buftest, sizeof(buftest)); 

option 2

change type of first argument of getsymboliclinktarget.

int getsymboliclinktarget(char (*)argv[1000], char *buf, size_t buf_size){ 

this require changes how use argv in function.

then, can use:

getsymboliclinktarget(&str2, buftest, sizeof(buftest)); 

option 3

use wrapper variable in calling function.

char* argv[2] = {0}; argv[1] = str2; getsymboliclinktarget(argv, buftest, sizeof(buftest)); 

this not require changes how use argv in function.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -