In a message dated 7/26/00 5:19:44 AM Eastern Daylight Time, 
[EMAIL PROTECTED] writes:

<< Hi
         I have tried with reading after a file close and file open and
 file rewind. Still i get 0 objects. can anyone provide some working
 code for file reading and writing.
 
 Thanks
 venkatesh
 
 int file( void )
 {
   FileHand tmpFile = NULL;
   Int32 written, read;
   char write_buffer[5] = "abcd";
   char read_buffer[5] = "    ";
 
   tmpFile = FileOpen (0, "ptt1.txt", 0, 0, fileModeReadWrite, NULL);
   if (tmpFile == NULL)
   {
    printf("Error opening file");
   }
   written = FileWrite (tmpFile, write_buffer, 1, 4, &err);
   printf("Bytes Written = %d.\n",(int)written);
 
   err = FileClose(tmpFile);
   if (err)
   {
    printf("Error closing file");
   }
 
   tmpFile = FileOpen (0, "ptt1.txt", 0, 0, fileModeReadWrite, NULL);
   if (tmpFile == NULL)
   {
    printf("Error opening file");
   }
   err  = FileRewind (tmpFile);
   read = FileRead (tmpFile, read_buffer, 1, 3, &err);
   printf("Bytes read = %d.\n",(int)read);
   err = FileClose(tmpFile);
   if (err)
   {
    printf("Error closing file");
   }
 }
  >>

The 'fileModeReadWrite' flag in the second call to FileOpen() may be 
truncating the contents of your file.  Since you are only interested in 
reading the file, see if there's just a read-only type of flag that you can 
use when you open the file the second time.

PS: The call to FileRewind() in your code doesn't do anything useful.  It's 
job is to reset the file pointer to the beginning of the file and its being 
called immediately after you have opened the file, when the file pointer is 
already positioned where FileRewind() would move.

Also, there's really no need to close the file handle and then reopen it.  
You should be able to do your FileWrite's, do the FileRewind() to reset the 
file pointer to the beginning of the file, and then start doing your 
FileRead's.  Note that in this case you need to use FileRewind() because you 
are not closing and reopening the file.

Hope this helps,
-Pete

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

Reply via email to