"Memory cannot be read"? 
Author Message
 "Memory cannot be read"?

http://www.*-*-*.com/ ;EN-
US;Q281735&ID=KB;EN-US;Q281735

This link shows the error I am getting but I cannot see
the error in my code. Any ideas?

Code:

/////////////////////
void Warehouse::Talley_Print()
{
        char tmp[42];
        char name[10];
        lcaseCnt=0;
        bBottomPrintFlag=0;

//open file for writing.
        //if ( (fp = fopen
("d:\\Bsmt\\TrayPack_Reports\\PSC051100.txt","w")) != NULL)
//      if ( (fp = fopen("c:\\talley_report.txt","w")) !=
NULL)
        strcpy( tmp, "d:\\Bsmt\\TrayPack_Reports\\" );
    strcpy( name, (char*)szOrderNo );
    strcat(tmp, name );
        strcat(tmp, ".txt" );
        fp = fopen(tmp,"w+");
        if ( (fp) != NULL)
        {
                // set this to the fetch size you want (64
rows per block in this case)
 const int block_size = 10000;
 int nItem = 0;

// create a statement object
 Statement st(pDb);

 // Storage for results etc...(in this case a menu/list of
items from the query)
 char** menu = new char* [block_size];
 char** Pcode = new char* [block_size];
 char** BoxNo = new char* [block_size];
 char** Weight = new char* [block_size];
 char** Desc = new char* [block_size];

 // Size the menu to the block size
 int i, menu_size = block_size;

// Make a field to bind for results
 szField _Pcode(55,block_size);
 szField _BoxNo(55,block_size);
 szField _Weight(55,block_size);
 szField _Desc(55,block_size);

 szField OrderNo(szOrderNo, sizeof(szOrderNo));
 szField Date(szDate,sizeof(szDate));

// Initialize the field - need to do this to check for
null returns
 for (int clearit=0; clearit < block_size; clearit++){
  strcpy( (char*)_Pcode.Value(clearit),"");
  strcpy( (char*)_BoxNo.Value(clearit),"");
  strcpy( (char*)_Weight.Value(clearit),"");
  strcpy( (char*)_Desc.Value(clearit),"");  
 }

// Fetch parameters
 UDWORD  crow;
 UWORD   rgfStatus[block_size];

// Set the cursor to static and set the block size for the
cursor
 st.SetCursorType(SQL_CURSOR_STATIC);
 st.SetFetchSize(block_size);

 st.BindParam(&OrderNo,SQL_PARAM_INPUT);
 st.BindParam(&Date,SQL_PARAM_INPUT);

// Execute a call to the database
st.ExecDirect( "SELECT BSMT.PCode, PRODUCTS.Prod_Desc,
BSMT.SerialNo,"
               " BSMT.Wgt"
                           " FROM BSMT INNER JOIN"
                           " PRODUCTS ON BSMT.PCode =
PRODUCTS.PCode"
               " WHERE BSMT.OrderNo =? AND"
                           " BSMT.Date =?"
                           " ORDER BY BSMT.PCode");

        //st.ExecDirect("SELECT ShipBy, Pcode, BoxNo, Wgt
FROM BSMT WHERE OrderNo=? AND Date=?");
// Bind the field defined above for the results
        st.BindCol(&_Pcode);        
        st.BindCol(&_Desc);
        st.BindCol(&_BoxNo);
        st.BindCol(&_Weight);

// Loop through the results
 while (st.FetchNext(&crow, rgfStatus) == SQL_SUCCESS)
 {
  // A new block was fetched (over 64 rows) - copy menu
objects and resize for next block
  if (menu_size - nItem < crow)
  {
   char** menu1 = new char* [nItem + crow];
   if (menu1 == NULL)
   {
    pDb->LogWrite("No more memory available!");
    break;
   }
   for (i = 0; i < nItem; i++)
        menu1[i] = menu[i];
   delete [] menu;
   menu = menu1;
   menu_size = nItem + crow;
  }

  // Loop through each record
  for (i = 0; i < crow; i++)
  {
    // Dynamically allocate more memory to the menu/list
   Pcode[nItem + i] = new char [strlen((char*)_Pcode.Value
(i)) + 1];
   Desc[nItem + i] = new char [strlen((char*)_Desc.Value
(i)) + 1];
   BoxNo[nItem + i] = new char [strlen((char*)_BoxNo.Value
(i)) + 1];
   Weight[nItem + i] = new char [strlen((char*)
_Weight.Value(i)) + 1];

    // Assign the results to the menu/list
   strcpy(Pcode[nItem + i], (char*)_Pcode.Value(i));    
   strcpy(Desc[nItem + i], (char*)_Desc.Value(i));
   strcpy(BoxNo[nItem + i], (char*)_BoxNo.Value(i));
   strcpy(Weight[nItem + i], (char*)_Weight.Value(i));

  }
    // Track the current record/row
  nItem += crow;
 }

//report
                fprintf(fp,"\n%60s","PRODUCT SHIPMENT
TALLEY SHEET");
                fprintf(fp,"\n\n%10s","Date:");
                fprintf(fp,"%13s",szDate);
                fprintf(fp,"%42s","Invoice #:");
                fprintf(fp,"%10s",szOrderNo);
                fprintf(fp,"\n\n%13s","Sold To:");
                fprintf(fp,"%10s",szOrderNo);
                fprintf(fp,"%40s","Ship To:");
                fprintf(fp,"%12s",szOrderNo);
                fprintf(fp,"\n\n\n\n\n%12s","P.O. #:");
                fprintf(fp,"%9s",szPoNo);
                fprintf(fp,"%37s","Ship By:");
                fprintf(fp,"%13s",szShipBy);
                fprintf(fp,"\n%79s","----------------------
-----------------------------------------------------");

                //do tots on fly or in sparate function,
hmmm.
                int k=0, lcaseCnt=0,lTotcaseCnt=0;
                float TotPwgt=0, TotOrdWgt=0;

                strcpy((char*)sztempProd,Pcode[k]);

                for(;k < nItem; k++){

                 if(strncmp((char*)sztempProd,Pcode[k],5)){
                 //all box#'s and weights
         fprintf(fp,"\n%8s",sztempProd);
             fprintf(fp,"%16s","Total Totes:");
                 fprintf(fp,"%6d",lcaseCnt);
                 fprintf(fp,"%25s","Total Weight:");
                 fprintf(fp,"%10.2f",TotPwgt);
                 fprintf(fp,"%5s","kgs");
                 if(!DbaseTest()){
                        fprintf(fp,"\n%16s%s%20s","***
Product ",sztempProd, " not on order ***");              

                        bBottomPrintFlag=1;
                 }//endif
                        else{
                         if(lSchedcaseCnt > lcaseCnt &&
lcaseCnt != 0){
                                 fprintf(fp,"\n%29s%3d%6s%
s","** This order is under by",(lSchedcaseCnt-lcaseCnt),"
totes of Product: ",sztempProd);
                                 bBottomPrintFlag=1;
                         }//endif
                         if(lSchedcaseCnt < lcaseCnt){
                                 fprintf(fp,"\n%28s%3d%6s%
s","** This order is over by",(lcaseCnt-lSchedcaseCnt),"
totes of Product: ",sztempProd);  
                                 bBottomPrintFlag=1;
                         }//endif
                        }//endelse

           //do call to new look up function here then
print discrepencies if there
                 //are any. + set bottom message flag

                 fprintf(fp,"\n%79s","---------------------
------------------------------------------------------");
                 strncpy((char*)sztempProd,Pcode[k],5);
                 TotPwgt=0;
                 lcaseCnt=0;
                 }//endif

         if((lcaseCnt%6)==0 && lcaseCnt!=0 && (!strncmp
((char*)sztempProd,Pcode[k],5)))
                 fprintf(fp,"%s","\n");

         if(lcaseCnt==0){
                   fprintf(fp,"\n%
13s","Product: "); //followed by prod# and name.
                   fprintf(fp,"%-8s",sztempProd);
                   fprintf(fp,"%-25s\n",Desc[k]);
                  }//endif

         lcaseCnt+=1;
         lTotcaseCnt+=1;
         TotPwgt+=(atof(Weight[k]));
         TotOrdWgt+=(atof(Weight[k]));                  
         fprintf(fp,"%12s",Weight[k]);
         }//endfor
        fprintf(fp,"\n%8s",sztempProd);
            fprintf(fp,"%16s","Total Totes:");
                fprintf(fp,"%6d",lcaseCnt);
                fprintf(fp,"%25s","Total Weight:");
                fprintf(fp,"%10.2f",TotPwgt);
                fprintf(fp,"%5s","kgs");
        if(!DbaseTest()){
                        fprintf(fp,"\n%16s%s%20s","***
Product ",sztempProd, " not on order ***");
                        bBottomPrintFlag=1;
                 }//endif
                        else{
                         if(lSchedcaseCnt > lcaseCnt &&
lcaseCnt != 0){
                                 fprintf(fp,"\n%29s%3d%6s%
s","** This order is under by",(lcaseCnt-lSchedcaseCnt),"
totes of Product: ",sztempProd);
                                 bBottomPrintFlag=1;
                         }//endif
                         if(lSchedcaseCnt < lcaseCnt){
                                 fprintf(fp,"%\n28s%3d%6s%
s","** This order is over by",(lSchedcaseCnt-lcaseCnt),"
totes of Product: ",sztempProd);  
                                 bBottomPrintFlag=1;
                         }//endif
                        }//endelse
                fprintf(fp,"\n%79s","----------------------
-----------------------------------------------------");
                ReversePrint(); //gets products items that
have not been added to order yet and are therefore not in
Bsmt table.
                //at end of report
                fprintf(fp,"\n\n%
79s","=====================================================
======================");
                fprintf(fp,"\n%26s","Manifiest Total
Totes:");
                fprintf(fp,"%10d",lTotcaseCnt);
                fprintf(fp,"%28s","Manifiest Total Wt:");
                fprintf(fp,"%10.2f",TotOrdWgt);
                fprintf(fp,"%5s","kgs");
                fprintf(fp,"\n%
79s","=====================================================
======================");
                if(bBottomPrintFlag){
                        fprintf(fp,"\n\n\n%
72s","********PLEASE SEE ABOVE FOR ORDER
DISCREPENCIES********");
                        bBottomPrintFlag=0;
                }//endif
                fprintf(fp,"\f");
                fclose(fp);

Quote:
}

else
{
        clrscr();
        cout << "\n\n***********" << endl << "Can't Print"
<< "\n***********";
        getch();

Quote:
}
}

Thanks in advance.


Sun, 11 Jul 2004 04:53:49 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Problem getting "memory cannot be read"

2. ERROR: memory cannot be "read"

3. Error "free"-ing "malloc"-ed memory

4. Memory could not be "read"

5. memory "read" error

6. ERROR: memory could not be "read"

7. The memory could not be "read"

8. The memory could not be "read"

9. "No memory" while plenty of memory

10. I am going to study "C"

11. MSDNMessageService "Cannot deserialize object"

12. Error "Cannot Load ActiveX component"

 

 
Powered by phpBB® Forum Software