View unanswered posts | View active topics It is currently Fri Dec 06, 2019 5:32 pm

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

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.

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
   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
      if (nNxtButtonPressed==2)
         while(nNxtButtonPressed==2){};  // left arrow decreases value
      nxtDisplayCenteredBigTextLine(6, "%3.1f", fParmToReadFloat); // update the display

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

Fri Oct 26, 2012 5:42 pm
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.