I am trying to cast an int value in a struct to a double. I am guessing I am screwing up the parenthesis somehow. I wasn't able to find anything useful in the forum or in google.

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; 
}

Your casts are fine; the problem is that you haven't initialized the values of start.x and edges.x1[0] yet, so they have whatever garbage was in them before the program was run (or zeroes, at best, if the memory is getting cleared by the system before use).

BTW, did you see my answer to your previous question? I think you'd be able to better structure your data if you followed my earlier advice.

Edited 2 Years Ago by Schol-R-LEA

Yes. I screwed up a comma in a pass to my function. Google wasn't giving me any useful results so I assumed it was a casting issue. I also couldn't find any examples of casting a struct value either

error: invalid operands to binary & (have ‘double’ and ‘double’)
This article has been dead for over six months. Start a new discussion instead.