I'm going to modify my pseudocode from above to provide more of the requested info (because posting the full code would be confusing and too complicated to make sense): (please let me know if any other aspects of the code still need to be added)
Code:
main( ) {
…
functionA( );
}
double functionA( ){
InHouseType *mystructure;
double MyArray[20] = {0.0};
for(i=0; i < NUM_MEMBERS; i++){
/* code to assign values to MyArray -- all are valid & verified by print statements */
/* the following call updates all of the values of MyArray */
mystructure = &InHouse_struct[i];
printf("Before call to functionB(): MyArray[0]= %f, MyArray[1] = %f, ... .\n", MyArray[0], MyArray[1], ...);
/* BEHAVIOR: all MyArray[ ] values printed at this point are correct -- no NANs */
…
functionB(…, …, MyArray);
printf(“Print Statement 1: MyArray[0] = %f, MyArray[1] = %f, …\n”, MyArray[0], MyArray[1], …);
BEHAVIOR: THE FIRST VALUE OF MyArray (i.e., MyArray[0]) is always NAN here, and the rest of the values look ok.
for(j=0; j < NDOF; j++){
… /* value of MyArray used but not changed here */
printf(“Print Statement 2: MyArray[0] = %f, MyArray[1] = %f, …\n”, MyArray[0], MyArray[1], …);
BEHAVIOR: ALL VALUES OF MyArray are ok here, including MyArray[0]; however, if I comment out Print Statement 1 above, then the first value of MyArray *here* is NAN, and the rest look ok. So, for some reason, the first value of MyArray[ ] that I print out after the call to functionB( ) returns, is always NAN.
…
} /* end for(j ) loop */
} /* end for(i ) loop */
} /* end functionA( ) */
________________________
Separate .c code file:
double functionB(…, …, MyArray[]){
printf(“Print Statement 3: MyArray[0] = %f, MyArray[1] = %f, …\n”, MyArray[0], MyArray[1], …);
BEHAVIOR: SOMETIMES THE FIRST VALUE OF MyArray[ ] (i.e., MyArray[0]) is NAN; during other code runs, this first value is fine. The rest of the MyArray values are ok.
/* code that assigns new values to the members of MyArray[ ] */
…
printf(“Print Statement 4: MyArray[0] = %f, MyArray[1] = %f, …\n”, MyArray[0], MyArray[1], …);
BEHAVIOR: ALL VALUES OF MyArray ARE ALWAYS OK HERE.
}
>> Moreover the NAN output could stem from the fact that you're trying to print a double as a float, tho' to be sure post the code.
I've never had a problem using %f to print a double value. Do you see any problems with the way I'm printing out, above?
Thanks for your help.