W
Wavelet
I want have one string array and want to assign them in
one sub-function. After that,it will be used in main funcion.
But it seems the following code doesn't work.How can I
do it with pointer?
#include <stdio.h>
#include <stdlib.h>
char *str[] = {"word1","word2"};
void sub(char **p)
{
p = str;
}
main()
{
char** argv= NULL;
sub(&argv);
printf("arg[0]=%s\n",argv);
printf("arg[1]=%s\n",argv+1);
}
=========Result=======
[linuxred@vike tmp]$ a.out
arg[0]=(null)
Segmentation fault
one sub-function. After that,it will be used in main funcion.
But it seems the following code doesn't work.How can I
do it with pointer?
#include <stdio.h>
#include <stdlib.h>
char *str[] = {"word1","word2"};
void sub(char **p)
{
p = str;
}
main()
{
char** argv= NULL;
sub(&argv);
printf("arg[0]=%s\n",argv);
printf("arg[1]=%s\n",argv+1);
}
=========Result=======
[linuxred@vike tmp]$ a.out
arg[0]=(null)
Segmentation fault