Hello,
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;
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!