1

I need help with using pointers to access 2 different values from the function I created. I would need these values for certain calculations in a separate function.

I have tried introducing a pointer in the function and assigning the inductance to it. But it's not printing anything.

This is my initial code before adding in the pointers.

 double values(double, double);

 int main(void)
 {
  values(a,b);

  system("PAUSE");

  return 0;

 }

 double values(double inductance, double capacitance)   
 {
   //a = inductance; b = capacitance

   printf("Please insert the inductance value (in mH):\n");
   scanf("%lf", &inductance);



  printf("Please insert the capacitance value (in microFarads):\n");
  scanf("%lf", &capacitance);

  printf("\n");
  }

This is one of the things I tried. I tried several others. But I ended up confusing myself even more.

  double values(double *inductance) 
  {

  double induct;

   printf("Please insert the inducatance value (in mH):\n");
   scanf("%lf", induct);

   *inductance = induct;

   //   printf("\n \n %p", induct);

    printf("\n");
   }
2
  • 2
    Possible duplicate of Pointers as function arguments in C Commented Mar 24, 2019 at 13:27
  • scanf("%lf", induct); --> scanf("%lf", &induct); Commented Mar 24, 2019 at 13:31

1 Answer 1

1
double values(double);

 int main(void)
 {
  double a;
  values(&a);//<----Send a Pointer of the var(the address of )

  system("PAUSE");

  return 0;

 }

double values(double *inductance) //<----change the var value by pointer.
{

   printf("Please insert the inducatance value (in mH):\n");
   scanf("%lf", inductance );

   printf("\n");
}
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.