
scanf() w/ 2D-array address offsets: HELP!
I don't give up too easily, but this one has got me ripping my hair out.
According to every C book I've checked, my syntax is correct (although
none cover the combined particulars of this situation).
I'm using Turbo C 2.0 on a 386 MS-DOS system, trying to scan
double-precision floats into a 2-D array via a function to which I pass
the address of the array. The specification is that I treat the array as
2-D, by acting upon its elements with a nested loop. The challenge that I
have inflicted upon myself is to adhere strictly to pointer notation.
Here are the relevant parts (verified by isolation):
#include <stdio.h>
void store2d(double (*)[5], int);
int main(void)
{
static double values[3][5];
store2d(values, 3);
/* ... */
return 0;
Quote:
}
void store2d(double (*ar)[5], int size)
{
int row, col;
for (row=0; row<size; row++, ar++)
for (col=0; col<5; col++) {
printf("Enter a type double number: ");
scanf("%lf", *ar+col);
}
Quote:
}
The code compiles without error or warning, but a run-time error message
appears directly after the prompt for the number:
scanf : floating point formats not linked
Abnormal program termination
I am aware that this is the same message that occurs when what scanf() is
given is not a pointer. I have double-checked the size and value of the
argument, its reference, and even its dereference (useless as it sounds) -
yet everything in the code seems to be the way it should. The problem
does not occur when the array is simplified to one dimension. When I
change the 2-D array to any simple data type other than floating point
types, the problem also disappears.
I'm not looking for a quick-fix - I really want to learn what is
preventing me from running this thing the way I want it. Am I going
overboard with the pointer notation? Is there an undocumented bug in
scanf() that would explain this phenomenon? Has anyone ever seen this before?
Obliged to Bearers of Solutions,
------- Matt Rafferty -------