c - 打印数组指针的C函数?
问题描述
我正在尝试制作一个打印出数组指针的 ac 程序,这是我尝试的
#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);
推荐阅读
- python - 在 For 循环中,如何解压缩“枚举”和另一个对三个变量的可迭代
- python - 我可以一次从一个文件夹中导入所有 Python 文件吗?
- java - HttpsURLConnection:使用 IDE JDK 可用于身份验证,但不适用于 JRE!这很奇怪
- python - 如何将用户输入与字典索引匹配?
- docker - 未经授权:拉取 sequenceiq/hadoop-docker:2.7.1 时需要身份验证
- machine-learning - 反向传播、交叉熵损失和 Softmax 函数
- sql-server - 在T-SQL(SQL Server)中将工作时间日期时间调整为下一个工作日上午8点
- c++ - Weird "reference to non-static member function must be called" error
- c - CPU 在访问全局变量时重置自定义 C 内核的执行
- javascript - ajax成功功能后更改文本区域的高度