[英]C function that prints pointer of an array?
我正在尝试制作一个可以打印出数组指针的交流程序,这是我尝试过的
#include <stdio.h>
#include <string.h>
void printArr(int index,char *arr);
char *str[] = {"heyyo","help"};
int main()
{
//printf(*(str+1)); --Works
printArr(1,str); // --No output
return 0;
}
void printArr(int index,char *arr){
printf(*(arr+index));
}
函数不起作用,因此没有任何输出
代码中存在类型不匹配。 str
是指向char数组的指针,而函数则采用指向char的指针。
test.c:11:16: warning: passing argument 2 of ‘printArr’ from incompatible pointer type
printArr(1,str); // --No output
^
test.c:4:6: note: expected ‘char *’ but argument is of type ‘char **’
void printArr(int index,char *arr);
void printArr(int index,char **arr){
printf("%s\n",*(arr+index));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.