nag_open_file (x04acc) (PDF version)
x04 Chapter Contents
x04 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_open_file (x04acc)

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_open_file (x04acc) opens a file for reading, writing or appending, and returns an associated file identifier.

2  Specification

#include <nag.h>
#include <nagx04.h>
void  nag_open_file (const char *filename, Integer mode, Nag_FileID *fileid, NagError *fail)

3  Description

nag_open_file (x04acc) opens a file for reading, writing or appending and returns an associated file identifier. This function is intended for use by callers of certain functions in Chapters e04 and f12 which use the file identifier for input or output of data.

4  References

None.

5  Arguments

1:     filename const char *Input
On entry: the name of the file to be opened. As special cases, an empty string or null pointer may be used to associate fileid with standard input or standard output. See the description of mode below.
Constraint: must contain a valid filename for the computer system being used.
2:     mode IntegerInput
On entry: specifies whether the file is to be opened for reading, writing or appending.
mode=0
The file is to be opened for reading.
If filename is an empty string or null pointer then fileid becomes associated with standard input.
mode=1
The file is to be opened for writing.
If filename is an empty string or null pointer then fileid becomes associated with standard output.
mode=2
The file is to be opened for appending.
If filename is an empty string or null pointer then fileid becomes associated with standard output.
Constraint: 0mode2.
3:     fileid Nag_FileID *Output
On exit: an identifier associated with the file to be read from, written to or appended to. This identifier will typically be passed to other NAG C Library functions.
4:     fail NagError *Input/Output
The NAG error argument (see Section 2.7 in How to Use the NAG Library and its Documentation).

6  Error Indicators and Warnings

NE_INT
On entry, mode=value.
Constraint: 0mode2.
NE_NOT_APPEND_FILE
Cannot open file value for appending.
NE_NOT_READ_FILE
Cannot open file value for reading.
NE_NOT_WRITE_FILE
Cannot open file value for writing.

7  Accuracy

Not applicable.

8  Parallelism and Performance

nag_open_file (x04acc) is not threaded in any implementation.

9  Further Comments

None.

10  Example

This example illustrates how to open a file for writing, write a line to the file using nag_write_line (x04bac) and close the file using nag_close_file (x04adc). The file is then reopened, the line read back using nag_read_line (x04bbc), and closed again.

10.1  Program Text

Program Text (x04acce.c)

10.2  Program Data

None.

10.3  Program Results

Program Results (x04acce.r)


nag_open_file (x04acc) (PDF version)
x04 Chapter Contents
x04 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2016