I found what I thought to be a great example of more complicated file access in RobotC on the official wiki: http://www.robotc.net/wiki/NXT_Functions_File_Access#ExampleBut then code I'm developed for a project with the help of that page was producing compile errors I couldn't figure out. So I tried compiling the example. Same errors. That code was written in Dec 2011, and is not compatible with the latest RobotC.

string sMessageToWrite = "ROBOTC IO test!"; // we will write this to the file string sMesageToWrite_2 = "A new line!"; // we will also write this to the file on the next line char incommingChar; // this will store each char as we read back in from the file string incommingString[5]; // this will store the final, fully-read strings (with new strings getting put into new indexes int nLineCounter = 0; // this will let us know which line we are on when reading and writing (used as the index to 'incommingString[]')

for(int i = 0; i < nFileSize; i++) // iterate through the file until we've hit the end: { ReadByte(hFileHandle, nIOResult, incommingChar); // read in a single byte

if(incommingChar == CR || incommingChar == LF) // if the incomming byte is a carriage return or a line feed: { if(incommingChar == LF) // if it's a line feed: nLineCounter++; // increment our index (will now store next char on a 'new line' (a new index into our 'incommingString[]') } else { incommingString[nLineCounter] += incommingChar; // append that byte (char) to the end of our final string, at the right index } } Close(hFileHandle, nIOResult); // close our file (DON'T FORGET THIS STEP!)

In these cases we know how to handle these commands correctly or - in case - we could simply refer to standard C references likehttp://www.cplusplus.com/reference/cstdio/and IMO there is no need to "invent" deviant RobotC commands if ANSI C commands already exist.

Who is online

Users browsing this forum: No registered users and 2 guests

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