开发者

changing value from function

I want to change a 2dim char array in a function.

I allocate the space like

char **u;
u = new char * [ MAX_DEPTH ];
for (i=0; i<MAX_DEPTH; i++)
    u[ i ] = new char [ BUFFER_SIZE ];

the function looks like

rem(char ***arr, int max_length, char *url)
{
    int idx=0;
    char * p;
    int i;

    p = strtok (url,"/"); 

    while (p != NULL && idx < max_length)
    {

        for (  i=0; i<maxUrlSize-1 && p[i] != '\0'; i++)
            (*arr)[idx][i] = p[i];
        for (     ; i< maxUrlSize-1; i++)
            (*arr)[idx][开发者_如何学Ci] = '\0';
    }
}

the function will be used in my main program.

rem( &u, MAX_LEN, url);

but after leaving the function there is nothing in. Could someone explain me how to use pointers in this way?


You need to change the reference to tmp in your function, to arr. You aren't accessing the parameter arr at all. Also, you do not need char *** here, since you aren't changing the space allocated to u. Instead, you should have parameter char **arr, which you access as arr[i][j]. And you should then pass u to rem, rather than &u.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜