Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 分配不兼容的指针类型(警告)_C_Compiler Warnings - Fatal编程技术网

C 分配不兼容的指针类型(警告)

C 分配不兼容的指针类型(警告),c,compiler-warnings,C,Compiler Warnings,问题是每次我尝试提交此代码时,都会显示以下消息: 来自不兼容指针类型的分配[默认情况下已启用] 警告是由aux=q引起的; 我应该如何使它们兼容 #include <stdio.h> #include <stdlib.h> typedef struct { int a, b, c, d; } t_cuatro; void order(t_cuatro * q); int main() { t_cuatro x = {5,6,2,8}; pri

问题是每次我尝试提交此代码时,都会显示以下消息:

来自不兼容指针类型的分配[默认情况下已启用]

警告是由aux=q引起的; 我应该如何使它们兼容

#include <stdio.h>
#include <stdlib.h>

typedef struct
{
    int a, b, c, d;
}
t_cuatro;

void order(t_cuatro * q);

int main()
{
    t_cuatro x = {5,6,2,8};
    printf("%d, %d, %d, %d\n", x.a, x.b, x.c, x.d);
    ordenar(&x);
    printf("%d, %d, %d, %d\n", x.a, x.b, x.c, x.d);
    return 0;
}

void order(t_cuatro  *q)
{
    int * aux;

    int aux2;

    int i,j;

    aux=q;

    for(i=0;i<4;i++)
    {
        for(j=i+1;j<4;j++)
        {
            if(*(aux + i)>*(aux + j))
               {
                   aux2 = *(aux+i);
                   *(aux+i) = *(aux+j);
                   *(aux+j) = aux2;

               }
        }
    }


}
#包括
#包括
类型定义结构
{
INTA、b、c、d;
}
t_cuatro;
无效命令(t_cuatro*q);
int main()
{
t_cuatro x={5,6,2,8};
printf(“%d、%d、%d、%d\n”、x.a、x.b、x.c、x.d”);
奥德纳尔&x;
printf(“%d、%d、%d、%d\n”、x.a、x.b、x.c、x.d”);
返回0;
}
无效订单(t_cuatro*q)
{
int*aux;
int aux2;
int i,j;
aux=q;

for(i=0;i
int*
struct t\u cuatro*
不兼容。无法“使”它们兼容

看起来您正在尝试对结构中的内容进行排序…但实际上您没有使用
order()
中的成员。我建议您使用数组(而不是四个变量:a、b、c和d):

然后在
order()
中,您可以将其分配给
int*

void order(t_cuatro  *q)
{
    int *aux = q->arr;
    /* remove the assignment aux = q; */
 ....
将阵列打印为:

for (size_t i = 0; i < sizeof x.arr/sizeof x.arr[0]; ++i)
printf("%d ", x.arr[i]); 
(大小i=0;i
int*
struct t\u cuatro*
不兼容。无法“使”它们兼容

看起来您正在尝试对结构中的内容进行排序…但实际上您没有使用
order()
中的成员。我建议您使用数组(而不是四个变量:a、b、c和d):

然后在
order()
中,您可以将其分配给
int*

void order(t_cuatro  *q)
{
    int *aux = q->arr;
    /* remove the assignment aux = q; */
 ....
将阵列打印为:

for (size_t i = 0; i < sizeof x.arr/sizeof x.arr[0]; ++i)
printf("%d ", x.arr[i]); 
(大小i=0;i其中一个是指向
int
的指针,另一个是指向
struct
的指针-不难理解如何将它们更改为相同类型以及整个逻辑(嵌套的
for
循环)当你在处理一个
struct
,而不是一个
int
数组时,它接近于未定义的行为。我知道一个是int,另一个是指向一个struct的指针,但问题是,我不知道如何在不改变整个程序的情况下使两者兼容,因为程序本身工作正常,但这个警告困扰着我ng me..其中一个是指向
int
的指针,另一个是指向
struct
的指针-应该不太难弄清楚如何将它们更改为相同类型以及整个逻辑(嵌套
for
循环)当你在处理一个
struct
,而不是一个
int
数组时,它接近于未定义的行为。我知道一个是int,另一个是指向一个struct的指针,但问题是,我不知道如何在不改变整个程序的情况下使两者兼容,因为程序本身工作正常,但这个警告困扰着我很好的回答。我特别赞成“你不能使它们兼容”,我正要说我自己。很好的回答。我特别赞成“你不能使它们兼容”,我正要说我自己。