View unanswered posts | View active topics It is currently Sat Nov 01, 2014 2:18 am






Reply to topic  [ 1 post ] 
V3.51 File IO bug 
Author Message
Rookie

Joined: Wed Jul 21, 2010 11:23 pm
Posts: 39
Post V3.51 File IO bug
The filename parameter for openread/openwrite for cannot be declared as a string constant, otherwise the functions fail.

The program below, which evolved largely from one of the the RobotC samples, shows the problem. If the "const" is removed from the filename declaration it properly reads and writes one editable value to a file. With the "const" in place it does not create the file and also fails to read the file even if it exists.


Code:
const string sFileName = "test2.txt";

TFileIOResult nIoResult;
TFileHandle hFileHandle;
int nFileSize = 100;
float  fParmToReadFloat = (float) 3.55;  // should only see this value if no file exists

task main()
{
   CloseAllHandles(nIoResult);                                                // make sure everything is closed
   wait1Msec(500);
   OpenRead(hFileHandle, nIoResult, sFileName , nFileSize);  // open the existing file
   ReadFloat(hFileHandle, nIoResult, fParmToReadFloat);         // read a single float value from it
   Close(hFileHandle, nIoResult);                                          // and close the file
   
   while(nNxtButtonPressed!=3)   // continue in editor until enter button is pressed
   {if (nNxtButtonPressed==1)
      {
         while(nNxtButtonPressed==1){};  // right arrow increases value
         fParmToReadFloat+=1;
      }
      if (nNxtButtonPressed==2)
      {
         while(nNxtButtonPressed==2){};  // left arrow decreases value
         fParmToReadFloat-=1;
      }
      nxtDisplayCenteredBigTextLine(6, "%3.1f", fParmToReadFloat); // update the display
   }

   Delete(sFileName, nIoResult);                     // delete pre-existing file (if any)
   nxtDisplayBigTextLine(0, "Deleted");
   wait1Msec(2000);
   nFileSize = 100;
   OpenWrite(  hFileHandle, nIoResult, sFileName, nFileSize); // create new file
   nxtDisplayBigTextLine(2, "Opened");
   wait1Msec(2000);
   WriteFloat( hFileHandle, nIoResult, fParmToReadFloat);  // write our value
   nxtDisplayBigTextLine(4, "Written");
   wait1Msec(2000);
   Close(hFileHandle, nIoResult);            // and close the file
   nxtDisplayBigTextLine(6, "Closed");
   wait1Msec(2000);
}


Fri Oct 26, 2012 5:42 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.