L
Louise Hoffman
Dear readers,
Full source code with data file at (50k):
http://www.sendspace.com/file/32ghfp
My C book says that an array is the same as a pointer to the array.
So I would really like to have fit_data.c to return a pointer to a 2
dimensional array, data_space.
How would you put char's into such an array?
That is what I am trying to do in the last for-loop in fit_data.c, but
doesn't seam to be valid.
Lots of love,
Louise =)
--- tit_data.c ---
char fit_data(double start_x, double slut_x,
double start_y, double slut_y,
double *x, double *y,
int n) {
char *data_space;
int size = X_BINS * Y_BINS * sizeof(char);
data_space = malloc(size);
if (data_space == 0) {
printf("Out of memory\n");
exit(EXIT_FAILURE);
}
/* Fill array with white space */
int i=0;
for(i=0; i<size; i++) {
*(data_space + i) = ' ';
}
/* check if a data point should be inserted, and in such case where
*/
i=0;
int ybin, xbin;
for (i=0; i<n; i++) {
if (x >= start_x && x <= slut_x &&
y >= start_y && y <= slut_y) {
/* where to put x */
xbin = (int) round( (x - start_x)/(slut_x - start_x)
*X_BINS );
/* where to put y */
ybin = (int) round( (y - start_y)/(slut_y - start_y)
*Y_BINS );
data_space[xbin][ybin] = '*';
}
}
return data_space;
}
--- tit_data.c ---
Full source code with data file at (50k):
http://www.sendspace.com/file/32ghfp
My C book says that an array is the same as a pointer to the array.
So I would really like to have fit_data.c to return a pointer to a 2
dimensional array, data_space.
How would you put char's into such an array?
That is what I am trying to do in the last for-loop in fit_data.c, but
doesn't seam to be valid.
Lots of love,
Louise =)
--- tit_data.c ---
char fit_data(double start_x, double slut_x,
double start_y, double slut_y,
double *x, double *y,
int n) {
char *data_space;
int size = X_BINS * Y_BINS * sizeof(char);
data_space = malloc(size);
if (data_space == 0) {
printf("Out of memory\n");
exit(EXIT_FAILURE);
}
/* Fill array with white space */
int i=0;
for(i=0; i<size; i++) {
*(data_space + i) = ' ';
}
/* check if a data point should be inserted, and in such case where
*/
i=0;
int ybin, xbin;
for (i=0; i<n; i++) {
if (x >= start_x && x <= slut_x &&
y >= start_y && y <= slut_y) {
/* where to put x */
xbin = (int) round( (x - start_x)/(slut_x - start_x)
*X_BINS );
/* where to put y */
ybin = (int) round( (y - start_y)/(slut_y - start_y)
*Y_BINS );
data_space[xbin][ybin] = '*';
}
}
return data_space;
}
--- tit_data.c ---