为什么 char* "stuff here"[int here] 的输出是 char*?

问题描述 投票:0回答:1

在我的代码中,有一行

char* chunktl[140];
将 chunktl 定义为字符数组,稍后的代码填充这些值是什么,但这不相关,还有另一行
int arrayloc = relx + 7 +(8-rely)*16;
将 arrayloc 定义为 int,什么是变量并不重要,但是错误

error: passing argument 1 of ‘pixrender’ makes integer from pointer without a cast [-Wint-conversion]
  206 |                                                 pixrender(chunktl[arrayloc]);
      |                                                           ~~~~~~~^~~~~~~~~~
      |                                                                  |
      |                                                                  char *
terraria.c:81:22: note: expected ‘char’ but argument is of type ‘char *’
   81 | char* pixrender(char a)
      |                 ~~~~~^


仍然出现并表明 chunktl[arrayloc] 是一个字符串?

我尝试将 arrayloc 转换为各种类型(无符号 int、long 等),但没有解决问题

arrays c
1个回答
0
投票

char* chunktl[140];
创建一个包含 140 个指针的数组 (
char *
)。

chunktl[arrayloc]
返回这些指针之一。

您将其中一点传递给

pixrender

pixrender
想要一个
char
,而不是指针。

未提供足够的信息来提供解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.