gpt4 book ai didi

c - 赋值从指针生成整数,无需在 C 中进行强制转换

转载 作者:行者123 更新时间:2023-11-30 15:10:57 25 4
gpt4 key购买 nike

我的数据库课上有一个项目,老师要求我们创建一个程序,根据属性计算关系的闭包。我输入了计算闭包的函数的第一部分,但编译器不断给出此警告:

warning : assignment makes integer from pointer without cast

这是函数和与之相关的结构:

typedef struct df {
char PG[20];
char PD[20];
} DF;
char *Closure(DF *T, char *C, int sizeFD, char att, int n) {
int i, j;
j = 0;
C[j] = att;
for (i = 0; i < sizeFD; i++) {
if (T[i].PG == &att) {
j++;
C[j] = T[i].PD; // this is where there's the warning
}
}
if (j == n)
exit(EXIT_SUCCESS);
return C;
}

我需要你的帮助,请为我指明正确的方向。

最佳答案

违规言论是:

C[j] = T[i].PD;

Cchar *,因此 C[j]char 并且不能赋值 T[i].PD,它是一个数组,衰减为指向 char 的指针。

请注意,T[i].PG == &att 始终为 false,因为 att 是局部变量,并且 T[i].PG > 是结构内的数组。

目前尚不清楚该代码试图执行什么操作。

关于c - 赋值从指针生成整数,无需在 C 中进行强制转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35928987/

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