Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fprintf(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                              fprintf(3C)



        _________________________________________________________________
        fprintf                                                  function
        Perform a formatted write to a file.
        _________________________________________________________________


        Calling Sequence

        #include <stdio.h>

        FILE *fp;
        int fprintf();
        char *format;
        fprintf(fp, format, arg ...);


        where
             fp is a pointer to the output FILE stream.

             format is a string containing two kinds of objects:

             ASCII characters that the function copies directly.

             Conversion specifications that start with %.

             Each arg is a valid C variable or constant.


        Description

        The fprintf function enables you to write to a file.  It replaces
        the format specifications with the successive argument(s) (arg
        ...) and writes the result to a file.  For details about
        conversion specifications, see the printf function.


        Returns

        The fprintf function returns -1 if an error occurs.  Otherwise,
        it returns the number of characters in the output.


        Related Functions

        See also the fscanf, printf, and sprintf functions.


        Example

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




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





                                                              fprintf(3C)



        #include <stdio.h>

        FILE   *fp, *fopen();
        int     i = 2, ibuf, atoi(), fprintf();
        double  dbuf, atof();

        main(argc, argv)
        int     argc;
        char    *argv[];
        {
            fp = fopen(argv[1], "a");
            fprintf(fp, "This program prints numerical data to a\n");
            fprintf(fp, "file in a variety of formats.\n\n");
            while (i < argc) {
                dbuf = atof(argv[i]);
                fprintf(fp, "%e in scientific notation =\n", dbuf);
                fprintf(fp, "%f in normal notation =\n", dbuf);
                ibuf = atoi(argv[i]);
                fprintf(fp, "%d decimal =\n%o octal =\n", ibuf, ibuf);
                fprintf(fp, "%x hexadecimal.\n\n",ibuf);
                i++;
            }
        }

        A call to the program test with the valid filename result_nos
        (which is empty) and the input numbers

        144
        3.1416
        -99.99e4

        generates in the file result_nos the output

        This program prints numerical data to a
        file in a variety of formats.

        1.440000e+02 in scientific notation =
        144.000000 in normal notation =
        144 decimal =
        220 octal =
        90 hexadecimal.

        3.141600e+00 in scientific notation =
        3.141600 in normal notation =
        3 decimal =
        3 octal =
        3 hexadecimal.

        -9.999000e+05 in scientific notation =
        -999900.000000 in normal notation =
        -99 decimal =



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





                                                              fprintf(3C)



        37777777635 octal =
        ffffff9d hexadecimal.




















































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



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