0

I am attempting to fill in a struct I have created in C, and for whatever reason it is not being reflected when I set a struct's parameters to 0. What am I doing wrong?

Here is the code:

struct Quad head_Quad, *temp_Quad;

head_Quad.ll_x = 0.0;
head_Quad.ll_y = 0.0;
head_Quad.side_length = 600;
temp_Quad = &head_Quad;
printf("head quad length: %d \n", head_Quad.side_length);
printf("temp quad length: %d \n", temp_Quad->side_length);

The printf is giving me 0. (temp was just an attempt to test if the value was set again)

Below is the struct itself:

typedef struct Quad
{
    double ll_x;    //lower left x point
    double ll_y;    //lower left y point
    double side_length;
}Quad;
3
  • oh boy :) thanks buddy @xing Commented Apr 30, 2017 at 20:22
  • 1
    Note that good compilers will warn you about such mismatches. For example, GCC with -Wall will do that. If you're using GCC, add -Wall -Wextra -Werror to your command line. Commented Apr 30, 2017 at 20:41
  • Turn compiler warnings on. Leave the switch on forever. Commented Apr 30, 2017 at 20:45

1 Answer 1

1

As @xing stated it was just the flag i was using in the printf statement, i should've known i had a for loop iterating through. Simple goof.

Instead of %d it should be %f

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.