I am a student at University of Phoenix and required to use the Miracle C compiler. I recently completed an assignment by using seperate functions to populate arrays of character strings, which worked well when built using Visual C++ Express Edition 2005. The problem was that using Miracle C to compile/build/execute the same source, creates issues. Here are some excerpts from my code:
// Function to populate the array of strings
int getStores(char *storeNames)
{
int storeNameIndex = 0;
storeNameIndex = MAX_STORE_NAME_LENGTH * 0;
sprintf(&(storeNames[storeNameIndex]),"Del Mar\0");
...
storeNameIndex = MAX_STORE_NAME_LENGTH * 2;
sprintf(&(storeNames[storeNameIndex]),"La Jolla\0");
}
// Portion of main function that iterates through and prints the store names:
/* Print the Store Name, Purchase Amount, and the Tax Amount */
printf("\t%s\t$%.2f\n", &(storeNames[storeNameIndex]), taxAmount);
The problem is that on every iteration the output is La Jolla. Through debugging I was able to establish that the array was populated correctly in the context of the function, but then seems to be corrupted as control is passed from the function back to main. Does anyone reading know of outstanding issues with Miracle C around memroy management or is Visual C++ Express just too forgiving of my poorly written code???
Thanks for any insite!!
-Dave