如何将称为函数的字符串数组中的特定元素的地址传递给另一个函数

时间:2017-09-28 07:52:02

标签: c arrays string pointers

这是我的示例程序

void first_call();
void second_call();
int main()
{
char *str[]={"We will teach you how to...",
              "Move a mountain",
              "Level a building",
              "Erase the past",
              "Make a million",
              "...all through C!"};
first_call(str);

return 0;
}

str传递给" first_call()" 现在我想要打印字符' i'来自" mountain"在第二个字符串。

void first_call(char **str)
{

printf("%s",str[1]); //to print second string,working

printf("%c",*(&str[1]+13));  //to print 'i' form second string
                             //but not working

second_call(&(&str[1]+13));  //to pass address of address of element of string
                              //not working,and giving error
}

我还想在second_call()中传递该特定地址。

void second_call(char ***s_element)
{
printf("\n%c",**s_element);  //not working
}

我应该怎么做。

1 个答案:

答案 0 :(得分:0)

改变这个:

printf("%c",*(&str[1]+13));

到此:

printf("%c", *(str[1] + 13));