User`s manual

Dynamic C Users Manual digi.com 139
10.1.6 Skeleton Program Using FS2
The following program uses some of the FS2 API. It writes several strings into a file, reads the file back
and prints the contents to the Stdio window.
For a more robust program, more error checking should be included. See the sample programs in the
Samples\FILESYSTEM folder for more complex examples, including error checking, formatting, parti-
tioning and other new features.
#use "FS2.LIB"
#define TESTFILE 1
main()
{
File file;
static char buffer[256];
fs_init(0, 0);
if (!fcreate(&file, TESTFILE) && fopen_wr(&file,TESTFILE))
{
printf("error opening TESTFILE %d\n", errno);
return -1;
}
fseek(&file, 0, SEEK_END);
fwrite(&file,"hello",6);
fwrite(&file,"12345",6);
fwrite(&file,"67890",6);
fseek(&file, 0, SEEK_SET);
while(fread(&file,buffer,6)>0) {
printf("%s\n",buffer);
}
fclose(&file);
}