Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <stdio.h>
    size_t fwrite( const void *buf,
                   size_t elsize,
                   size_t nelem,
                   FILE *fp );

Description:
    The fwrite function writes nelem elements of elsize bytes each to the
    file specified by fp.

Returns:
    The fwrite function returns the number of complete elements successfully
    written.  This value will be less than the requested number of elements
    only if a write error occurs.  When an error has occurred,  errno
    contains a value indicating the type of error that has been detected.

Example:
    #include <stdio.h>

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

    void main()
      {
        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(std), 1, fp );
          printf( "%d record written\n", i );
          fclose( fp );
        }
      }

Classification:
    ANSI

Systems:
    All, Netware

See Also:
    ferror, fopen

See Also: ferror

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson