Page 1 of 1

NXC File commands

Posted: 26 Nov 2010, 17:40
by borntoown
Hello.
How to create, read, write, write from variable to file and the other way, a file using NXC?
Thanks.

Re: NXC File commands

Posted: 26 Nov 2010, 17:50
by dudmaster
Oh, Hi!

Here is a test program that writes a deletes a file, creates a file, and writes to a file:

Code: Select all

task main() {
byte handle;
int cnt;
string str = "For AnotherRandomPerson C=";
DeleteFile ("Hello.txt");
CreateFile("Hello.txt", 300, handle);
WriteString(handle, str, cnt);
CloseFile(handle);
}
Questions accepted!

Re: NXC File commands

Posted: 26 Nov 2010, 18:04
by borntoown
You should have explained. I'm asking about that...
Ok:

1) Why there is a byte variable?
2)What's handle?
3)300 what?
4)WriteString for text, what about numbers? logic?
5) what is cnt?
6)WriteString(handle, STR?, CNT?)? Why is those?

thanks

Re: NXC File commands

Posted: 26 Nov 2010, 19:56
by physics-matt
Have you looked at the documentation?

http://bricxcc.sourceforge.net/nbc/nxcd ... index.html

Also, have a look at the guide

http://www.hsu-hh.de/download-1.4.1.php ... XwQ3q7fePG

section 3.8, "Loader Module".

There's also been a discussion on this sort of thing in another thread:

https://sourceforge.net/apps/phpbb/mind ... ?f=1&t=255

Hopefully you will find the answers you need in there somewhere!

Matt

Re: NXC File commands

Posted: 27 Nov 2010, 09:07
by borntoown
Nope, sorry. I didnt get it yet.

Re: NXC File commands

Posted: 29 Nov 2010, 20:18
by afanofosc
physics-matt wrote: Also, have a look at the guide

http://www.hsu-hh.de/download-1.4.1.php ... XwQ3q7fePG
I would recommend getting the NXC Guide from the NBC/NXC website rather than from another site.

http://bricxcc.sourceforge.net/nbc/

You'll find the guide in the NXC Docs section.

John Hansen

Re: NXC File commands

Posted: 29 Nov 2010, 20:24
by afanofosc
Also, the NXC help files include a number of examples that show how to do file i/o in NXC. If you have specific questions about specific API functions it would be easier to help you than trying to guess exactly what information you need in order to get you going.

The API functions generally all use a file handle which can be stored in a byte variable. If you open an existing file or create a new file you have to keep the handle if you want to do anything else with the file, such as close it or write to it or read from it. When you create a new file on the NXT you have to provide the size of the file. That's the "300" that was used in the example code posted above. You can use whatever size you like. Once you write that many bytes to the file you create then you can't write any more data to the file. The API functions that let you write to a file return status codes that help you determine whether the operation succeeded or if something went wrong what exactly went wrong.

The NXC Guide and help files do a reasonably decent job of explaining a lot of this. Definitely read the loader module section.

John Hansen

Re: NXC File commands

Posted: 29 Nov 2010, 22:04
by physics-matt
afanofosc wrote: http://bricxcc.sourceforge.net/nbc/

You'll find the guide in the NXC Docs section.
I could't find the old version of the NXC guide on the BricxCC site - before it became 2000 something pages of function definitions. I like the old version because I thought it had quite a lot more explanation in it (or perhaps I just haven't found it in the new version?).

Any particular reason you changed it, other than the fact it is probably now quite out of date?

Matt

Re: NXC File commands

Posted: 30 Nov 2010, 00:47
by afanofosc
To the best of my knowledge the larger guide contains everything that the old guide had in it. If not then I would like to know about it. Though the PDF is many pages longer the bulk of the old guide content should be right at the start of the new guide. And there is always PDF search and bookmarks for the sections of interest.

John Hansen