Call by Reference

Hi, i've been struggling with learning C. I'm trying to take an input with the "get_input" function, pass it to main, then pass it to "get_output", cube it, then print the result. from what I can tell my program isn't loading the input into memory. I appreciate any help, thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  #include <stdio.h>
#include <stdlib.h>
 
int get_input(double *reliability); 
void put_output(double reliability);
 
int main()
{
 
double series, reliability;
 
get_input(&reliability); 
put_output(reliability);
printf("series = %f",series);
 
}
 
 
int get_input(double *reliability)
{
 
printf("Enter individual component reliability: ");
   scanf("%f", &reliability);
 
}
 
 
void put_output(double reliability)
{
 
double series;
 
series = (reliability*reliability*reliability);
    
}
Try scanf("%f", reliability);

At this point in the code, reliability is already a pointer, pointing at the memory you want to input to be stored in.

Learn about pointers: http://www.cplusplus.com/articles/EN3hAqkS/
Topic archived. No new replies allowed.