DADiSP Worksheet Functions > Function Categories > File Manipulation > FPRINTF

 

FPRINTF

Purpose:

Performs formatted output to a file.

Syntax:

FPRINTF("filename", "control", arg1, arg2, ..., argN)

"filename"

-

A string. Name of output file. The file must have been previously opened with FOPEN.

"control"

-

A string. Format control string. Conforms to the C/C++ language SPRINTF specification.

argN

-

Number or string to format. See SPRINTF for details.

Returns:

1 if successful, else 0.

Example:

/* write out useful series attributes */
writeval(fname, series)
{
    if (fopen(fname, "w") != 1)
    {
        error(sprintf("writeval - cannot open %s", fname));
    }
 
    fprintf(fname,"Xoffset : %g\n", xoffset(series));
    fprintf(fname,"Deltax  : %g\n", deltax(series));
    fprintf(fname,"Length  : %d\n", length(series));
    fprintf(fname,"Mean    : %g\n", mean(series));
    fprintf(fname,"Sum     : %g\n", sum(series));
 
    fclose(fname);
}

 

writeval("test.txt", gsin(100,.01)+1)

 

The file "test.txt" contains the following text:

 

 Xoffset : 0

 Deltax  : 0.01

 Length  : 100

 Mean    : 1

 Sum     : 100

Remarks:

See SPRINTF for details on formatting syntax and capabilities.

See Also:

FCLOSE

FCLOSEALL

FGETS

FOPEN

FPUTS

SPRINTF