f_write


Use this function to write data into a file at the current file position. The current file position is increased by the number of bytes successfully written. The file must be opened with “w”, “w+”, "a+", "r+", or “a”.

Format

long f_write (
    void *     bbuf,
    long       size,
    long       size_st,
    F_FILE *   filehandle)

Arguments

Argument Description Type
bbuf The buffer which contains the data. void *
size The size of the items to be written. long
size_st The number of items to write. long
filehandle The handle of the file. F_FILE *

Return values

Return value Description
number The number of items written successfully.
-1 Operation failed.

Example

void myfunc( void )
{
    F_FILE *file;
    char *string = "ABC";
    file = f_open( "myfile.bin", "w" );
    if (!file)
    {
        printf( "File cannot be opened!" );
        return;
    }
    if (f_write( string, 1, 3, file )!= 3)  /* Write 3 bytes */
    {                       
        printf( "Not all bytes were written" );
    }
    f_close( file );
}