我正在开发一种名为 BPML 的自定义编程语言,我想尝试更新名为 的输出函数say()。
C 中的最新版本:
void say(char *text) {
printf("%s", text);
}
Run Code Online (Sandbox Code Playgroud)
Python 的最新版本:
def say(text):
print(text, end = '')
Run Code Online (Sandbox Code Playgroud)
在 C 中,我希望它像 Python 的print()函数一样,只需在函数中输入变量即可,但在 C 中情况并非如此,因为您仍然必须使用适当类型的变量。
这就是为什么我在编写的程序中出现错误:
#include <stdio.h>
void say(char *text);
int main() {
int number = 21;
say(number);
}
void say(char *text) {
// Output function
}
Run Code Online (Sandbox Code Playgroud)
错误:
P1.c:7:9: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'char *' [-Werror,-Wint-conversion]
say(number);
^~~~~~
Run Code Online (Sandbox Code Playgroud)
我仍然需要使用itoa()中的函数<stdlib.h>,但我没有想到,因为它在 CI …