### fwrite -- Write Items

Format

>     #include <stdio.h>
>     size_t fwrite(const void *buffer, size_t size, size_t count,
>                      FILE *stream);

Language Level: ANSI, POSIX, XPG4
fwrite writes up to count items, each of size bytes in length, from buffer to the output stream.

Return Value
fwrite returns the number of full items successfully written, which can be fewer than count if an error occurs.

Example
This example writes NUM long integers to a stream in binary format.

    #include <stdio.h>

    #define FILENAME "myfile.dat"

    #define  NUM  100
    int main(void)
    {
       FILE *stream;
       long list[NUM];
       int numwritten;
       int i;
       stream = fopen("FILENAME", "w+b");
       /* assign values to list[] */
       for (i=0; i<=NUM; i++)
           list[i]=i;
       numwritten = fwrite(list, sizeof(long), NUM, stream);
       printf("Number of items successfully written = %d\n", numwritten);
       return 0;

       /****************************************************************
          The output should be:

          Number of items successfully written = 100
       ****************************************************************/
    }

fopen -- Open Files
fread -- Read Items
read -- Read Into Buffer
write -- Writes from Buffer to File
<stdio.h>