Reputation: 33
I have prompted the user for 5 inputs in the main and saved them into an array called array. I've checked the array in main and it prints out the values as they were entered. However, when I pass it to a function which I've included below, I get the output that the array contains all 0 values. What am I doing wrong?
conversion(float array[], int size)
{
float add = 0.0;
float change, num;
printf("\nThe array is: \n");
for (i=0;i < size;i++)
{
printf("%.2f\n",&array[i]);
}
/*calculate and store the conversion values in a new array*/
for(i=0; i<s; i++)
{
num = array[i];
change = (num*100.50);
for(j=0; j<1; j++)
{
printf("\n %.2f your number is %.2f in float percent\n", &num, &change);
}
}
}
Upvotes: 2
Views: 42
Reputation: 93
Like Johnny Mopp said you have an extraneous &
,
But depending on the size of the array you're dealing with you may just want to pass a pointer to the function instead.
Upvotes: 0
Reputation: 4788
&cArray[i]
you don't need to address of the ith element in order to print it, you just need the ith element
Change
printf("%.2f\n",&cArray[i]);
printf("\n %.2f in Celsius is %.2f in Fahrenheit\n", &temp, &con);
to
printf("%.2f\n",cArray[i]);
printf("\n %.2f in Celsius is %.2f in Fahrenheit\n", temp, con);
The same with con
, printf()
doesn't need the address of a scalar variable in order to print it.
Upvotes: 2