C
Christopher Smith
All -
I'm a bonafied newbie to programming and am having trouble using
Arrays. Also, I'm not quite sure how to ask the question intelligently,
but here it goes...
I've got his array that I populate with data. I've got another array
that I want to populate with different data. (The reason I'm doing this
is I have time-series data that I want to analyze and so I need to
generate a series of statistics off the underlying data and then compare
them.)
The problem is that after I successfully populate the first array I then
move on to populating the second array, which seems to -- magically as
far as I've been able to figure out -- reset the ArrayA[0][0] value to
last value in ArrayA. So, if I 'ArrayA' looked like this at the end of
step one:
1 2 3
4 5 6
7 8 9
3 4 5
In step two, when the system had col = 2 and row = 3 and should be
filling ArrayB at location ArrayB[3][2] with some data -- call it X--,
what happens is ArrayA[0][0] actually gets overwritten with the value 5
at ArrayA[3][2]. I have absolutely no idea why this happening...using
GNU debugger, I've been able trace the overwrite down this last step...
I'm assuming that is some sort of memory addressing error or something,
and I have read everything I could find out there on the web about using
arrays but w/ no luck.
------------------------------------------------------------------------
/* step one */
for (col=0; col < num_columns; col++) {
for (row=0; row < num_rows; row++) {
ArrayA[row][col]=various_data;
}
}
/* step two */
for (col=0; col < num_columns; col++) {
for (row=0; row < num_rows; row++) {
ArrayB[row][col]=other_various_data;
}
}
I'm a bonafied newbie to programming and am having trouble using
Arrays. Also, I'm not quite sure how to ask the question intelligently,
but here it goes...
I've got his array that I populate with data. I've got another array
that I want to populate with different data. (The reason I'm doing this
is I have time-series data that I want to analyze and so I need to
generate a series of statistics off the underlying data and then compare
them.)
The problem is that after I successfully populate the first array I then
move on to populating the second array, which seems to -- magically as
far as I've been able to figure out -- reset the ArrayA[0][0] value to
last value in ArrayA. So, if I 'ArrayA' looked like this at the end of
step one:
1 2 3
4 5 6
7 8 9
3 4 5
In step two, when the system had col = 2 and row = 3 and should be
filling ArrayB at location ArrayB[3][2] with some data -- call it X--,
what happens is ArrayA[0][0] actually gets overwritten with the value 5
at ArrayA[3][2]. I have absolutely no idea why this happening...using
GNU debugger, I've been able trace the overwrite down this last step...
I'm assuming that is some sort of memory addressing error or something,
and I have read everything I could find out there on the web about using
arrays but w/ no luck.
------------------------------------------------------------------------
/* step one */
for (col=0; col < num_columns; col++) {
for (row=0; row < num_rows; row++) {
ArrayA[row][col]=various_data;
}
}
/* step two */
for (col=0; col < num_columns; col++) {
for (row=0; row < num_rows; row++) {
ArrayB[row][col]=other_various_data;
}
}