User`s manual

Dynamic C Users Manual digi.com 145
10.2.2.2 Using the File System
The rest of fat_create.c demonstrates how to use the file system once it is up and running.
File Name: Samples\FileSystem\fat_create.c
prealloc = 0;
rc = fat_Open( first_part, "HELLO.TXT", FAT_FILE, FAT_CREATE,
&my_file, &prealloc );
if (rc < 0) {
printf("fat_Open() failed with return code %d\n", rc);
exit(1);
}
rc = fat_Write( &my_file, "Hello, world!\r\n", 15 );
if (rc < 0) {
printf("fat_Write() failed with return code %d\n", rc);
exit(1);
}
rc = fat_Close(&my_file);
if (rc < 0) {
printf("fat_Close() failed with return code %d\n", rc);
}
rc = fat_Open( first_part, "HELLO.TXT",FAT_FILE, 0, &my_file,
NULL);
if (rc < 0) {
printf("fat_Open() (for read) failed, return code %d\n", rc);
exit(1);
}
rc = fat_Read( &my_file, buf, sizeof(buf));
if (rc < 0) {
printf("fat_Read() failed with return code %d\n", rc);
}
else {
printf("Read %d bytes:\n", rc);
printf("%*.*s", rc, rc, buf); // Print a string which is not NULL terminated
printf("\n");
}
fat_UnmountDevice( first_part->dev );
printf("All OK.\n");
return 0;
}