c语言编程铸造结构值

c语言编程铸造结构值,c,struct,C,Struct,我试图将结构中的int值转换为double。我猜我不知怎么搞砸了括号。我在论坛或谷歌上找不到任何有用的东西 我添加了更多信息 struct START { int x; int y; double heuristic; }; struct SHAPES { int x [100]; int y [100]; double heuristic [100]; int has_visited [100]; int num_point

我试图将结构中的int值转换为double。我猜我不知怎么搞砸了括号。我在论坛或谷歌上找不到任何有用的东西

我添加了更多信息

struct START
{
    int x; 
    int y;
    double heuristic;
};

struct SHAPES
{
    int x [100]; 
    int y [100];
    double heuristic [100];
    int has_visited [100];
    int num_points;
    int *link;
};

struct LINE
{
    int x1 [100];
    int y1 [100];
    int x2 [100];
    int y2 [100];
};

double addition(double x, double y)
{
    return x + y;
}

int main(int argc, char *argv[])
{
int kk = 0;
double x = 0;
double y = 0;
double z = 0;    
struct START start;
struct END end;
struct SHAPES shapes[100];
struct LINE edges;


x = (double)start.x;
y = (double)edges.x1[kk];
z = addition((double)start.x, (double)edges.x1[kk])
return 0; 
}

我试着运行你的代码,在这里和那里做了一些修改,这对我来说很有效,除了我必须注释掉DoubleEdge。x1[kk]因为x1在任何结构中都不存在,而且我认为你需要使用形状而不是边,我不知道你是否在代码的其他部分定义了边。 以下是我尝试过的:

#include <stdio.h>
#include <string.h>
#include <math.h>
struct START
{
    int x; 
    int y;
    double heuristic;
};

struct SHAPES
{
    int x [100]; 
    int y [100];
    double heuristic [100];
    int has_visited [100];
    int num_points;
    int *link;
};

struct LINE
{
    int x1 [100];
    int y1 [100];
    int x2 [100];
    int y2 [100];
};



void main()
{
    int kk = 0;
    double x = 0;
    double y = 0;
    double z = 0;    
    struct START start;
    //struct END end;
    struct SHAPES shapes[100];
    struct LINE edges;

    start.x = 123;
    (double)start.x;
    edges.x1[kk] = 143;
    (double)edges.x1[kk];
    printf("%d\t%d\n",start.x,edges.x1[kk]);
    z = (sqrt(start.x+edges.x1[kk]));
    printf("%f",z);

}

这段代码毫无意义,无法编译。梅因在哪里?作业在哪里?kk来自哪里?在一个函数之外挂起的这两个强制转换是不合法的。你的强制转换没有任何意义。请在使用cast的地方发布整个表达式。有关如何在c中键入cast,请参见此,它应该类似于:double temp=double start.x;这也应该在主{}内@编辑:我添加了主。我仍然不知道我是怎么铸造错误的。有一种结构叫做边缘。这是一种线型结构。它有一个名为x1的子项。@JammuPapa很抱歉,我添加了这个结构。当我回答这个问题时,它不是问题的一部分。这就是我为什么要写我不知道你是否在代码的其他部分定义了边。@JammuPapa你知道我是如何铸造错误的吗?有没有一种特殊的方法可以在函数中执行?我已经更改了代码,它运行得很好。要知道y有%f,请参阅