I'm a C newbie (first time using C at university) and after reading a few books, I still have problem implementing & understanding structures and pointers.

I have the following structure:

typedef struct data {
double average;
Tdata stat = {0};

Now I have two functions which are closely linked together. I use one to compute the average and the second one to use the average for additional purposes. I have the functions written (each works on its own), I just have troubles linking it with the structure.

double avg (Tdata *stat){
// variables
// reading from stdin until EOF
// computing
stat->average = average; }

double funct (Tdata *stat) {
double i;
double x;
// reading from stdin until EOF
i = x - (stat->average); }

The problem I'm having is that I'm not sure, once I call the function 'avg' from main, how to call the function 'funct' with the average number that was computed in 'avg', so the function can use the value from the structure. I call 'funct' from inside 'avg' (or vce versa), it just returns random values.

Thank you!

7 Years
Discussion Span
Last Post by Ancient Dragon

I assume you did not post all the code in those two function. If you are getting just some random values then you are probably using some uninitialized variables in those function. Post the entire program so that we can see what you are doing.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.