C++ scanf/printf of array
I've written following code:
int main() {
double A[2];
printf("Enter coordinates of the point (x,y):\n");
scanf("%d,%d", &A[0], &A[1]);
printf("Coordinates of the point: %d, %d", A[0], A[1]);
return 0;
}
It's acting like this:
Enter coordinates of the point (x,y):
3,5
Coordinates of the point: 3, 2开发者_StackOverflow673912
How is it possible, that 5 converts into 2673912??
You are reading double values using the decimal integer format (%d). Try using the double format (%lf) instead...
scanf("%lf,%lf", &A[0], &A[1])
精彩评论