By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,233 Members | 1,774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,233 IT Pros & Developers. It's quick & easy.

struct and C

P: 6

I am completely new to computer programming and I have trouble using structures in a correct way in a C program.

After testing several components of the program, the problem is basically this:

#include <stdio.h>

/*define structure with containing three coordinates*/
struct point {
float x;
float y;
float z;
struct point ptx0;
ptx0.x= 0;
ptx0.y= 1;
ptx0.z= 0;
struct point ptx1;
ptx1.x= 0;
ptx1.y= 2;
ptx1.z= 0;
printf("%d\n", ptx1.y);

Executing this program prints an ever changing value, I suppose whatever is located at that moment in memory storage. How do I simply get it to print the value '2'?
In the end, I am using values from an external file and I want to use the values of these structures in further calculations (so not just printing them of course). The problem is thus to transfer the input to the algorithm.

Thank you for your comments!
Mar 19 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 1,510
the %d conversion specification
Expand|Select|Wrap|Line Numbers
  1. printf("%d\n", ptx1.y);
is for printing int variables whereas yours are float
try the %f conversion specification
Expand|Select|Wrap|Line Numbers
  1. printf("%f\n", ptx1.y);
Mar 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.