Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/f/fwrite.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/f/fwrite.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/f/fwrite.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/f/fwrite.html on line 8

fwrite()

Write elements to a file

Synopsis:

#include <stdio.h>

size_t fwrite( const void* buf,
               size_t size,
               size_t num,
               FILE* fp );

Arguments:

buf
A pointer to a buffer that contains the elements that you want to write.
size
The size of each element to write.
num
The number of elements to write.
fp
The stream to which to write the elements.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The fwrite() function writes num elements of size bytes each to the stream specified by fp.

Returns:

The number of complete elements successfully written; if an error occurs, this is less than num.

Errors:

If an error occurs, errno is set to indicate the type of error.

Examples:

#include <stdio.h>
#include <stdlib.h>

struct student_data {
    int student_id;
    unsigned char marks[10];
};

int main( void )
{
    FILE *fp;
    struct student_data std;
    int i;

    fp = fopen( "file", "w" );
    if( fp != NULL ) {
        std.student_id = 1001;

        for( i = 0; i < 10; i++ ) {
            std.marks[i] = (unsigned char)(85 + i);
        }

        /* write student record with marks */
        i = fwrite( &std, sizeof( struct student_data ), 1, fp );
        printf( "Successfully wrote %d records\n", i );

        fclose( fp );
        
        if( i == 1 ) {
            return EXIT_SUCCESS;
        }
    }

    return EXIT_FAILURE;
}

Classification:

ANSI, POSIX 1003.1

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

See also:

errno, ferror(), fopen()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/f/fwrite.html on line 170

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/f/fwrite.html on line 170