Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fwrite(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                               fwrite(3C)



        _________________________________________________________________
        fwrite                                                   function
        Write a number of records to a specified file.
        _________________________________________________________________


        Calling Sequence

        #include <stdio.h>

        FILE *fp;
        char *buffer;
        int numrec, numbyt, numwrit;
        numwrit = fwrite(buffer, numbyt, numrec, fp);


          where   buffer is a byte pointer to a user-provided buffer.
                  numbyt is the number of bytes for each record.
                  numrec is the number of records to write.
                  fp is a pointer to a FILE stream.
                  numwrit is the number of records actually written.



        Description

        Use the fwrite function to write records to a specified file.
        The function will write the number of records you indicate, of
        the length you specify.  The include file stdio.h defines fwrite.

        Since the hardware representations for byte and word pointers
        differ, stdio.h defines fwrite as a macro which converts the
        buffer pointer to a byte pointer.


        Returns

        The function returns the number of whole records written, or 0
        for an error condition if nothing was written.


        Related Functions

        See also the fread function in this chapter, and the write
        function in the Programmer's Reference for the DG/UX System,
        Volume 1.


        Example

        /* Program test for the fwrite() function */



        DG/UX 4.00                                                 Page 1
               Licensed material--property of copyright holder(s)





                                                               fwrite(3C)



        #include <stdio.h>
        #define MAXBYT  64

        FILE    *fpi, *fpo, *fopen();
        char    stringbuf[MAXBYT];
        int     atoi(), numread, numrec, numbyt, numwrit;

        main(argc, argv)
        int     argc;
        char    *argv[];
        {
            fpi = fopen(argv[1], "r");
            fpo = fopen(argv[2], "w");

            numrec  = atoi(argv[3]);
            numbyt  = atoi(argv[4]);
            numread = fread(&stringbuf, numbyt, numrec, fpi);
            numwrit =  fwrite(stringbuf, numbyt, numrec, fpo);


            printf("You specified %d records of %d bytes.\n",
                   numrec, numbyt);
            printf("Number of records actually read = %d.\n",
                   numread);
            printf("Number of records actually written = %d.\n",
                   numwrit);
        }

        A call to the program test with the valid filename fin, which
        contains 9876543210, the valid filename fout, and the arguments 3
        and 2 generates in the output file fout

        987654

        and at the terminal

        You specified 3 records of 2 bytes.
        Number of records actually read = 3.
        Number of records actually written = 3.















        DG/UX 4.00                                                 Page 2
               Licensed material--property of copyright holder(s)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026