错误的无效操作数到二进制&(具有'int **'和'int *')

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

我正在尝试找出三角形的三个边的长度,然后按顺序对其进行排序,看看是否形成了三角形。我必须使用struct,但是会出现此错误。我的编译器是Dev C ++,并且此问题的局限性是三角形的三点应为Integer。并且结构的标记名称应为“ Point”。我需要你的帮助。

*****编辑****此代码的错误是“对二进制&(具有'int **'和'int *')无效的操作数”]

#include <stdio.h>
#include <math.h> 

typedef struct {
    int x;
    int y;
} Point;

int main()
{
    Point p1, p2, p3;    

    int temp;

    printf("please input first Point\n");
    scanf("%lf %lf", &p1.x &p1.y);

    printf("second Point\n");
    scanf("%lf %lf", &p2.x &p2.y);

    printf("Third Point\n");
    scanf("%lf %lf", &p3.x &p3.y); 

    int aX = p2.x - p1.x;    
    int aY = p2.y - p1.y;    

    int a = sqrt(pow(aX, 2) + pow(aY, 2));

    int bX = p3.x - p2.x;    
    int bY = p3.y - p2.y;   

    int b = sqrt(pow(bX, 2) + pow(bY, 2));

    int cX = p3.x - p1.x;   
    int cY = p3.y - p1.y;   

    int c = sqrt(pow(cX, 2) + pow(cY, 2));

    if (a >= b){
        temp = b;
        b = a;
        a = temp;
    }
    if (b >= c){
        temp = c;
        c = b;
        b = temp;
    }
    if (a >= b){
        temp = b;
        b = a;
        a = temp;
    }

    if(c< a + a){
        printf("ture");
    }
    else{printf("false");}

    return 0;
}

什么问题?

c pointers struct
2个回答
2
投票

此错误消息是因为编译器认为您正在尝试使用带有参数&&p1.x的二进制p1.y运算符(按位与),这没有意义。

反过来,这是因为您缺少某些函数参数之间的逗号;例如,此:

    scanf("%lf %lf", &p1.x &p1.y);

应该是这个:

    scanf("%d %d", &p1.x, &p1.y);

((请注意,我也纠正了格式说明符,对于%d,它是%lf,而不是int。]


0
投票

带参数&p1.xp1.y的二进制运算符(按位与)的使用也是错误的。我建议您更多地参考Input-output operations

我确定了您的代码,只有代码而不是理论。

#include <stdio.h>
#include <math.h> 

typedef struct Triangles{
    int x;
    int y;
} ;

int main()
{
    struct Triangles p1;
    struct Triangles p2;
    struct Triangles p3;   

    int temp;

    printf("please input first Point\n");
    scanf("%d %d", &p1.x ,&p1.y);

    printf("second Point\n");
    scanf("%d %d", &p2.x ,&p2.y);

    printf("Third Point\n");
    scanf("%d %d", &p3.x ,&p3.y); 

    int aX = p2.x - p1.x;    
    int aY = p2.y - p1.y;    

    int a = sqrt(pow(aX, 2) + pow(aY, 2));

    int bX = p3.x - p2.x;    
    int bY = p3.y - p2.y;   

    int b = sqrt(pow(bX, 2) + pow(bY, 2));

    int cX = p3.x - p1.x;   
    int cY = p3.y - p1.y;   

    int c = sqrt(pow(cX, 2) + pow(cY, 2));

    if (a >= b){
        temp = b;
        b = a;
        a = temp;
    }
    if (b >= c){
        temp = c;
        c = b;
        b = temp;
    }
    if (a >= b){
        temp = b;
        b = a;
        a = temp;
    }

    if(c< a + a){
        printf("ture");
    }
    else{printf("false");}

    return 0;
}

[忘记提及格式说明符%lf(用于双精度)是错误的,对于** int *。*干杯,必须为%d

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