In an attempt to debug this problem, I have added printf statements to see what is happening when the code is running.
The printf statement containing “#103D” gives a good value for “FirstPtr” but then its value changes.
I am using Borland C++ IDE to write 16 bit code for a picoFlash single board computer with a 186 compatible processor and 512K of Ram. I am adding code to an existing program that takes 183 pages to print. I have checked the “check stack overflow” option. The compiler and linker don’t give any error messages.
I don’t know what other information I should inclue because I have no idea what is happening.
How can I get to the bottom of this problem?
Code:
void DownloadAFile(char *strDirectory,char *strFileName,char *strRxBlock, int intOffset)
{
char *FirstPtr; //Pointer used to parse the incomming Request
char strNrChars[4]; //Number of characters to follow
int intNrChars; //Number of characters following next
int intLen; //Length of string
char strLength[4]; // 4 char string length
char *SPtr; //Pointer to the Line Input String
static char strLineInput[1024]; //String used for input
char *RspPtr; //Pointer to strResponseString
static char strResponseString[120];
char *ShortRspPtr;
char strShortResponseString[120]; //Without Rec #
char strCommandString[100];
char strFullFileName[80];
static char strOldFullFileName[80];
char strRecordNumber[4]; //Requested Record Number
int intRecordNumber; //Requested Record Number
int intSameFileFlag;
static FILE *TxtDLFilePtr;
char strTmpStr[80];
static int intLastRecordRead;
int intLastRecordReadPlus1;
int intContinueRecs; //1 => Continue reading records
int intBlockNr;
char strRecNr[4];
//Skip code here
//Pick intRecordNumber
FirstPtr = &strRxBlock[0]; //to 1
printf("#103 ok not term strRxBlock = %s\n", FirstPtr); //ok
printf("#103B s/b=1 Ptr @ strRxBlock[0] = %p\n", FirstPtr); //ok
FirstPtr+= intOffset; //Beginning of # char in Rec # to 29
printf("#103C s/b=29 Ptr @ Nr char in RecordNr = %p\n", FirstPtr); //ok
// TempPtr = FirstPtr;
strncpy (strNrChars,FirstPtr,4); //Nr chars in Record # ok
//The value of FirstPtr printed with the following line is ok = 5E7E:0AE4
printf("#103D after strncpy FirstPtr = %p\n", FirstPtr); //ok
strNrChars[4] = '\0';
//The value of FirstPtr printed with the following line has changed = 5E7E:0A00
printf("#103E after strncpy FirstPtr = %p\n", FirstPtr); //ok
printf("#104 ok strNrChars in Record Nr = %s\n",strNrChars); //Nr chars in Record # 4 ok
printf("#103F after strncpy FirstPtr = %p\n", FirstPtr); //ok
intNrChars = atoi(strNrChars);
printf("#103G after strncpy FirstPtr = %p\n", FirstPtr); //ok
printf("#105 ok intNrChars = %d\n",intNrChars); // = 4 ok
printf("#103H after strncpy FirstPtr = %p\n", FirstPtr); //ok
//More code follows