Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fread(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                                fread(3C)



        _________________________________________________________________
        fread                                                    function
        Read a number of records from a file.
        _________________________________________________________________


        Calling Sequence

        #include <stdio.h>

        char *buffer;
        FILE *fp;
        int numrec, numbyt, numread;
        numread = fread(buffer, numbyt, numrec, fp);



          where   buffer is a byte pointer to a user-provided buffer.

                  numbyt is the number of bytes per record.

                  numrec is the number of records to read.

                  fp is a pointer to a FILE stream.

                  numread is the number of records actually read.



        Description

        The fread function reads records from a specified file.  It reads
        the number of records you specify that are of the length you
        specify.  The include file stdio.h defines this function.

        Since the hardware representation for byte pointers differs from
        that of word pointers, dg_stdio.h defines a macro fread to force
        the first argument to a byte pointer.


        Returns

        The function returns the number of whole records that it read
        before an error or end of file occurred.  This function returns 0
        if it read no records.


        Related Functions

        See also the fwrite function.




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





                                                                fread(3C)



        Example

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

        #include <stdio.h>

        FILE    *fopen(), *fp;
        char    buffer[100];
        int     atoi(), numrec, numbyt, numread;

        main(argc, argv)
        int     argc;
        char    *argv[];
        {
            fp = fopen(argv[1], "r");
            numrec = atoi(argv[2]);
            numbyt = atoi( argv[3] );

            printf("Number of records read = %d\n",
                   numread = fread(buffer, numbyt, numrec, fp));
        }

        A call to the program test with the valid filename input_nos,
        which contains 0123456789, and the arguments 8 and 2 generates
        the output

        Number of records read = 5



























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



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