I have to work with eclipse in C. I wrote a simple program, but I have a problem with a printf command which doesn’t work properly. Any idea?
Here is the code :
#include <stdio.h>
void change(double *x, double *y)
{
double help = *x;
*x = *y;
*y = help;
return;
}
int main()
{
double x=0, y=0;
printf("please give a value to a \n ");
scanf("%f",&x);
printf("please give a value to b \n");
scanf("%f",&y);
printf("x=%.2f\t y=%.2f\n",x,y);
printf("will give \n");
change(&x,&y);
printf("x=%.2f\t y=%.2f\n",x,y);
return 0;
}
So the problem is that I dont’t get this first printf.
All your values are
doublefor which you have to use%lf. Buut you are using%fwhich invokes undefined behaviour.Change
%fto%lfin your scanfs and prints.