| Description | The function fopen opens a file for reading or writing. The parameter filename is a pointer defining the file to open. The parameter mode is a pointer defining the access type. The function is included in the library RL-FlashFS. The prototype is defined in the file stdio.h. filename can include a path. If the path does not exist, the subfolders are created. filename can have the following prefixes: | Drive Prefix | Description |
|---|
| "" | Default Drive system as defined in the file Config_File.c. | | "F:" or "F0:" | Flash drive | | "S:" or "S0:" | SPI Flash drive | | "R:" or "R0:" | RAM drive | | "M:" or "M0:" | Memory Card drive 0 | | "M1:" | Memory Card drive 1 | | "U:" or "U0:" | USB Flash drive 0 | | "U1:" | USB Flash drive 1 | | "N:" or "N0:" | NAND Flash drive |
The parameter mode can have the following values: | Mode | Description |
|---|
| "r" | Opens a file for reading. | | "w" | Opens an empty file for writing. If the file exists, the content is destroyed. If the file does not exist, an empty file is opened for writing. | | "a" | Opens a file for appending text. If the file already exists, data is appended. If the file does not exist, an empty file is opened for writing. |
|
| Example |
#include <rtl.h>
#include <stdio.h>
void tst_fopen (void) {
FILE *f;
f = fopen ("Test.txt","r"); /* Open a file from default drive. */
if (f == NULL) {
printf ("File not found!\n");
}
else {
// process file content
fclose (f);
}
f = fopen ("M:\\Temp_Files\\Dump_file.log","w"); /* Create a file in subfolder on SD card.*/
if (f == NULL) {
printf ("Failed to create a file!\n");
}
else {
// write data to file
fclose (f);
}
}
|