hi ,I think this piece of code will help you to read and write a file in palm
 
int readdata(unsigned char *PalmproductUnqID)
{
   FileHand securityfile;
   Err errp;
   Int32 count = 0;
   Int32 total = 0;
   Int32 fileSizeP;
   SFdata dummydata;
   FILE * secfile;
   char buff[40];
   UInt8 *bufferP;


   securityfile = FileOpen(0,SECFILE,0,0,fileModeReadOnly,&errp);
   if(errp)
      Display(errp);
   else
   {    
        #if IFDEBUG   
        FrmCustomAlert(SecurityAlert, "fopen for read success","?", "cc");
        #endif
    }
       
  
   FileTell (securityfile,&fileSizeP,&errp);//give you the size of the file
   MemSet(&dummydata,0,sizeof(SFdata));
   #if IFDEBUG      
   StrPrintF(buff,"filesize- %ld",fileSizeP);
   FrmCustomAlert(SecurityAlert, buff,"?", "cc");
   #endif

   count = FileRead(securityfile,&dummydata,1,sizeof(SFdata),&errp); //read the content
   #if IFDEBUG
   StrPrintF(buff,"read m-%c%c%c%c",dummydata.productuniqueID[0],dummydata.productuniqueID [1],dummydata.productuniqueID[2],dummydata.productuniqueID[3]);
   FrmCustomAlert(SecurityAlert,buff ,"?", "cc");
   #endif  
   if(errp)
   {
   
     #if IFDEBUG 
     FrmCustomAlert(SecurityAlert, "error in read","?", "cc");
     StrPrintF(buff,"error- %d totol - %d",errp,total);
     FrmCustomAlert(SecurityAlert, buff,"?", "cc");
     #endif  
     Display(errp);
   }
   else
   {
      #if IFDEBUG 
     FrmCustomAlert(SecurityAlert, "fread success","?", "cc");   
     StrPrintF(buff,"count- %ld",count);
     FrmCustomAlert(SecurityAlert, buff,"?", "cc");
     #endif
   }

     memcpy(PalmproductUnqID,&dummydata.productuniqueID,sizeof(dummydata.productuniqueID));

   errp = FileClose(securityfile);
   if(errp)
   {
     #if IFDEBUG 
     FrmCustomAlert(SecurityAlert, "error in FileClose","?", "cc");  
     #endif
     Display(errp);
    
   }

return 1;
}

int create_file(SFdata sfdata)//SFcontents = 64 bytes
{
   FileHand securityfile;
   Err errp;
   Int32 count = 0;
   char buff[40];
   
   securityfile = FileOpen(0,SECFILE,0,0,fileModeReadWrite,&errp);
   count = FileWrite(securityfile,&sfdata,1,sizeof(SFdata),&errp);
   
   if(errp)
  {
     #if IFDEBUG
     FrmCustomAlert(SecurityAlert, "error in write","?", "cc");
     #endif
     Display(errp);
   }  

   
   errp = FileClose(securityfile);
   if(errp)
   {
      #if IFDEBUG
     FrmCustomAlert(SecurityAlert, "error in FileClose","?", "cc");
     #endif
     Display(errp);
    
    }     
    #if IFDEBUG
   StrPrintF(buff,"create_securityfile success- %ld",count);
   FrmCustomAlert(SecurityAlert, buff,"?", "cc");
   #endif

return 1;
}

with cheers ,
shankari.

 
On 1/6/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
I am new to Palm programming, how can I place a Text file in the Palm and read it through my application ? I am trying to make an applicaiton which could read simple documents ( text files) on the palm.


--
For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/

-- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/

Reply via email to