gpt4 book ai didi

c - 我应该如何清除这些错误,为什么会出现这些错误?

转载 作者:行者123 更新时间:2023-12-02 10:44:49 25 4
gpt4 key购买 nike

从'int(*)()'分配给'int'的结果是从指针产生整数,而没有强制转换[-Werror = int-conversion]
给出一些背景:

int functionA(){
int a;
....//some operation on a
return a;
}

void functionB(){
int b = functionA;
}
错误消息出现在第
int b = functionA;
我不断收到的另一个错误是:
错误:“]”标记之前的预期表达式
给出上下文:
struct cat{
char name[10];
} cats[10];

void functionC(char name[]){
cats[0].name = name[];
}
错误发生在cats [0] .name = name [];

最佳答案

the error message appears at line

int b = functionA;
您忘记了括号:
int b = functionA();
在C语言中,首选 int functionA(void)(不带参数的函数)而不是 int functionA()(不带参数数量的函数)
struct cat{
char name[10];
} cats[10];

void functionC(char name[]){
cats[0].name = name[];
}
这里 cats[0].name是一个数组,数组名称是不可修改的左值,而是:
strcpy(cats[0].name, name);
或更好:
snprintf(cats[0].name, sizeof cats[0].name, "%s", name); // Avoid buffer overflows

关于c - 我应该如何清除这些错误,为什么会出现这些错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63751222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com