  | 
		
		
			
			
Compaq C
Compaq C Run-Time Library Reference Manual for 
OpenVMS Systems
 
 
 
fgets
 
Reads a line from the specified file, up to one less than the specified 
maximum number of characters or up to and including the new-line 
character, whichever comes first. The function stores the string in 
str.
 
 
Format
#include <stdio.h>
char *fgets (char *str, int maxchar, FILE 
*file_ptr);
 
  
Function Variants This function also has variants named
_fgets32
 and
_fgets64
 for use with 32-bit and 64-bit pointer sizes, respectively. See 
 Section 1.10 for more information on using pointer-size-specific 
 functions.
 
Arguments
str
A pointer to a character string that is large enough to hold the 
information fetched from the file.
maxchar
The maximum number of characters to fetch.
file_ptr
A file pointer.
 
 
Description
This function terminates the line with a null character (\0).
Unlike
gets
,
fgets
 places the new-line character that terminates the input line into the 
 user buffer if more than maxchar characters have not already 
 been fetched.
When the file pointed to by file_ptr is opened in record mode,
fgets
 treats the end of a record the same as a new-line character, so it 
 reads up to and including a new-line character or to the end of the 
 record.
  
 
Return Values
  
    | 
      x
     | 
    
Pointer to
      str.
     | 
   
  
    | 
      NULL
     | 
    
Indicates the end-of-file or an error. The contents of
      str are undefined if a read error occurs.
     | 
   
 
 
 
Example
 
  
    
       
      
#include <stdio.h> 
#include <stdlib.h> 
#include <unixio.h> 
 
main() 
{ 
    FILE *fp; 
    char c_ptr[130]; 
 
    /* Create a dummy data file  */ 
 
    if ((fp = fopen("file.dat", "w+")) == NULL) { 
        perror("open"); 
        exit(1); 
    } 
 
    fprintf(fp, "this is a test\n") ; 
    fclose(fp) ; 
 
    /* Open a file with some data -"this is a test"   */ 
 
    if ((fp = fopen("file.dat", "r+")) == NULL) { 
       perror("open error") ; 
        exit(1); 
    } 
 
    fgets(c_ptr, 130, fp); 
    puts(c_ptr);        /* Display what fgets got.  */ 
    fclose(fp); 
 
    delete("file.dat") ; 
} 
 |   
 
 
fgetwc
 
Reads the next character from a specified file, and converts it to a 
wide-character code.
 
 
Format
#include <wchar.h>
wint_t fgetwc (FILE *file_ptr);
 
  
 
Arguments
file_ptr
A pointer to the file to be accessed.
 
 
Description
Upon successful completion, the
fgetwc
 function returns the wide-character code read from the file pointed to 
 by file_ptr and converted to type
wint_t
. If the file is at end-of-file, the end-of-file indicator is set, and 
WEOF is returned. If an I/O read error occurred, then the error 
indicator is set, and WEOF is returned.
Applications can use
ferror
 or
feof
 to distinguish between an error condition and an end-of-file condition.
  
 
Return Values
  
    | 
      x
     | 
    
      The wide-character code of the character read.
     | 
   
  
    | 
      WEOF
     | 
    
Indicates the end-of-file or an error. If a read error occurs, the 
function sets
errno
 to one of the following:
- EALREADY -- An operation is already in progress on the same file.
 - EBADF -- The file descriptor is not valid.
 - EILSEQ -- Invalid character detected.
  
     | 
   
 
 
 
fgetws
 
Reads a line of wide characters from a specified file.
 
 
Format
#include <wchar.h>
wchar_t *fgetws (wchar_t *wstr, int maxchar, FILE 
*file_ptr);
 
  
Function Variants This function also has variants named
_fgetws32
 and
_fgetws64
 for use with 32-bit and 64-bit pointer sizes, respectively. See 
 Section 1.10 for more information on using pointer-size-specific 
 functions.
 
Arguments
wstr
A pointer to a wide-character string large enough to hold the 
information fetched from the file.
maxchar
The maximum number of wide characters to fetch.
file_ptr
A file pointer.
 
 
Description
This function reads wide characters from the specified file and stores 
them in the array pointed to by wstr. The function reads up to 
maxchar-1 characters or until the newline character is read, 
converted, and transferred to wstr, or until an end-of-file 
condition is encountered. The function terminates the line with a null 
wide character.
fgetws
 places the newline that terminates the input line into the user buffer, 
 unless maxchar characters have already been fetched.
 
 
Return Values
  
    | 
      x
     | 
    
Pointer to
      wstr.
     | 
   
  
    | 
      NULL
     | 
    
Indicates the end-of-file or an error occurred. The contents of
wstr are undefined if a read error occurs. If a read error 
occurs, the function sets
errno
. For a list of possible
errno
 values, see
fgetwc
       in this section.
     | 
   
 
 
 
Example
 
  
    
       
      
#include <stdlib.h> 
#include <stdio.h> 
#include <locale.h> 
#include <wchar.h> 
 
main() 
{ 
    wchar_t wstr[80], 
           *ret; 
    FILE *fp; 
 
    /* Create a dummy data file  */ 
 
    if ((fp = fopen("file.dat", "w+")) == NULL) { 
        perror("open"); 
        exit(1); 
    } 
 
    fprintf(fp, "this is a test\n") ; 
    fclose(fp) ; 
 
   /* Open a test file containing : "this is a test" */ 
 
    if ((fp = fopen("file.dat", "r")) == (FILE *) NULL) { 
        perror("File open error"); 
        exit(EXIT_FAILURE); 
    } 
 
    ret = fgetws(wstr, 80, fp); 
    if (ret == (wchar_t *) NULL) { 
        perror("fgetws failure"); 
        exit(EXIT_FAILURE); 
    } 
 
    fputws(wstr, stdout); 
    fclose(fp); 
    delete("file.dat"); 
} 
 |   
 
 
fileno
 
Returns the file descriptor associated with the specified file pointer.
 
 
Format
#include <stdio.h>
int fileno (FILE *file_ptr);
 
  
 
Argument
file_ptr
A file pointer.
 
 
Description
If you are using DEC C Version 5.2 or lower, undefine the
fileno
 macro:
 
  
    
       
      
#if defined(fileno) 
#undef fileno 
#endif 
 
 |   
 
 
Return Value
  
    | 
      x
     | 
    
      Integer file descriptor.
     | 
   
  
    | 
      --1
     | 
    
      Indicates an error.
     | 
   
 
 
 
finite  (ALPHA ONLY)
 
Returns the integer value 1 (True) when its argument is a finite 
number, or 0 (False) if not.
 
 
Format
#include <math.h>
int finite (double x);
 
int finitef (float x);
 
int double finitel (long double x);
 
  
 
Argument
x
A real value.
 
 
Description
The
finite
 functions return 1 when -Infinity < x < +Infinity. They 
 return 0 when |x| = Infinity, or x is a NaN.
 
 
floor
 
Returns the largest integer less than or equal to the argument.
 
 
Format
#include <math.h>
double floor (double x);
 
float floorf (float x);  (ALPHA ONLY)
 
long double floorl (long double x);  (ALPHA ONLY)
 
  
 
Argument
x
A real value.
 
 
Return Values
  
    | 
      n
     | 
    
      The largest integer less than or equal to the argument.
     | 
   
 
 
 
fmod
 
Computes the floating-point remainder.
 
 
Format
#include <math.h>
double fmod (double x, double y);
 
float fmodf (float x, float y);  (ALPHA ONLY)
 
long double fmodl (long double x, long double y); 
 (ALPHA ONLY)
 
  
 
Arguments
x
A real value.
y
A real value.
 
 
Description
The
fmod
 functions return the floating-point remainder of the first argument 
 divided by the second. If the second argument is 0, the function 
 returns 0.
 
 
Return Values
  
    | 
      x
     | 
    
The value
f, which has the same sign as the argument
x, such that
x ==
i *
y +
f for some integer
i, where the magnitude of
f is less than the magnitude of
      y.
     | 
   
  
    | 
      0
     | 
    
Indicates that
      y is 0.
     | 
   
 
 
 
fopen
 
Opens a file by returning the address of a FILE structure.
 
 
Format
#include <stdio.h>
FILE *fopen (const char *file_spec, const char 
*a_mode);  (ANSI C)
 
FILE *fopen (const char *file_spec, const char 
*a_mode, ...); (COMPAQ C EXTENSION)
 
  
 
Arguments
file_spec
A character string containing a valid file specification.
a_mode
The access mode indicator. Use one of the following character strings: 
"r", "w", "a", "r+", 
"w+", "rb", "r+b", "rb+", 
"wb", "w+b", "wb+", "ab", 
"a+b", "ab+", or "a+".
These access modes have the following effects:
 
  - "r" opens an existing file for reading.
  
 - "w" creates a new file, if necessary, and opens the file 
  for writing. If the file exists, it creates a new file with the same 
  name and a higher version number.
  
 - "a" opens the file for append access. An existing file is 
  positioned at the end-of-file, and data is written there. If the file 
  does not exist, the Compaq C RTL creates it.
  
The update access modes allow a file to be opened for both reading and 
writing. When used with existing files, "r+" and 
"a+" differ only in the initial positioning within the file. 
The modes are as follows:
 
  - "r+" opens an existing file for read update access. It is 
  opened for reading, positioned first at the beginning-of-file, but 
  writing is also allowed.
  
 - "w+" opens a new file for write update access.
  
 - "a+" opens a file for append update access. The file is 
  first positioned at the end-of-file (writing). If the file does not 
  exist, the Compaq C RTL creates it.
  
 - "b" means binary access mode. In this case, no conversion 
  of carriage-control information is attempted.
  
...
Optional file attribute arguments. The file attribute arguments are the 
same as those used in the
creat
 function. For more information, see the
creat
 function.
 
 
Description
If a version of the file exists, a new file created with
fopen
 inherits certain attributes from the existing file unless those 
 attributes are specified in the
fopen
 call. The following attributes are inherited:
  Record format
   Maximum record size
   Carriage control
   File protection.
 
If you specify a directory in the file name and it is a search list 
that contains an error, Compaq C for  OpenVMS Systems interprets it as a file open 
error.
 
The file control block can be freed with the
fclose
 function, or by default on normal program termination.
  
 
Return Values
  
    | 
      x
     | 
    
      File pointer.
     | 
   
  
    | 
      NULL
     | 
    
Indicates an error. The constant NULL is defined in the
<stdio.h>
 header file to be the NULL pointer value. The function returns NULL to 
 signal the following errors:
- File protection violations
 - Attempts to open a nonexistent file for read access
 - Failure to open the specified file
  
     | 
   
 
 
 
fp_class  (ALPHA ONLY)
 
Determine the class of IEEE floating-point values.
 
 
Format
#include <math.h>
int fp_class (double x);
 
int fp_classf (float x);
 
int fp_classl (long double x);
 
  
 
Arguments
x
An IEEE floating-point number.
 
 
Description
These functions determine the class of the specified IEEE 
floating-point number, returning a constant from the
<fp_class.h>
 header file. They never cause an exception, even for signaling NaNs 
 (Not-a-Number). These functions implement the recommended
class(x)
 function in the appendix of the IEEE 754-1985 standard for binary 
 floating-point arithmetic. The constants in
<fp_class.h>
 refer to the following classes of values:
  
    | 
      FP_SNAN
     | 
    
      Signaling NaN (Not-a-Number)
     | 
   
  
    | 
      FP_QNAN
     | 
    
      Quiet NaN
     | 
   
  
    | 
      FP_POS_INF
     | 
    
      +Infinity
     | 
   
  
    | 
      FP_NEG_INF
     | 
    
      --Infinity
     | 
   
  
    | 
      FP_POS_NORM
     | 
    
      positive normalized
     | 
   
  
    | 
      FP_NEG_NORM
     | 
    
      negative normalized
     | 
   
  
    | 
      FP_POS_DENORM
     | 
    
      positive denormalized
     | 
   
  
    | 
      FP_NEG_DENORM
     | 
    
      negative denormalized
     | 
   
  
    | 
      FP_POS_ZERO
     | 
    
      +0.0 (positive zero)
     | 
   
  
    | 
      FP_NEG_ZERO
     | 
    
      --0.0 (negative zero)
     | 
   
 
 
 
Return Values
  
    | 
      x
     | 
    
A constant from the
<fp_class.h>
       header file.
     | 
   
 
 
 
fpathconf
 
Retrieves file implementation characteristics.
 
 
Format
#include <unistd.h>
long int fpathconf (int filedes, int name);
 
  
 
Arguments
filedes
An open file descriptor.
name
The configuration attribute to query. If this attribute is not 
applicable to the file specified by the filesdes argument,
fpathconf
 returns an error.
 
 
Description
This function allows an application to retrieve the characteristics of 
operations supported by the file system underlying the file named by 
the filesdes argument. Read, write, or execute permission of 
the named file is not required, but you must be able to search all 
directories in the path leading to the file.
Symbolic values for the name argument are defined in the
<unistd.h>
 header file as follows:
 
  
    | 
      _PC_LINK_MAX
     | 
    
The maximum number of links to the file. If the
      filedes argument refers to a directory, the value returned 
      applies to the directory itself.
     | 
   
  
    | 
      _PC_MAX_CANON
     | 
    
      The maximum number of bytes in a canonical input line. This is 
      applicable only to terminal devices.
     | 
   
  
    | 
      _PC_MAX_INPUT
     | 
    
      The number of types allowed in an input queue. This is applicable only 
      to terminal devices.
     | 
   
  
    | 
      _PC_NAME_MAX
     | 
    
      Maximum number of bytes in a filename (not including a terminating 
      null). The byte range value is between 13 and 255. This is applicable 
      only to a directory file. The value returned applies to filenames 
      within the directory.
     | 
   
  
    | 
      _PC_PATH_MAX
     | 
    
      Maximum number of bytes in a pathname (not including a terminating 
      null). The value is never larger than 65,535. This is applicable only 
      to a directory file. The value returned is the maximum length of a 
      relative pathname when the specified directory is the working directory.
     | 
   
  
    | 
      _PC_PIPE_BUF
     | 
    
Maximum number of bytes guaranteed to be written atomically. This is 
applicable only to a FIFO. The value returned applies to the referenced 
object. If the
      path argument refers to a directory, the value returned 
      applies to any FIFO that exists or can be created within the directory.
     | 
   
  
    | 
      _PC_CHOWN_RESTRICTED
     | 
    
      The value returned applies to any files (other than directories) that 
      exist or can be created within the directory. This is applicable only 
      to a directory file.
     | 
   
  
    | 
      _PC_NO_TRUNC
     | 
    
      Returns 1 if supplying a component name longer than allowed by NAME_MAX 
      causes an error. Returns 0 (zero) if long component names are 
      truncated. This is applicable only to a directory file.
     | 
   
  
    | 
      _PC_VDISABLE
     | 
    
      This is always 0 (zero); no disabling character is defined. This is 
      applicable only to a terminal device.
     | 
   
 
 
 
Return Values
  
    | 
      x
     | 
    
The resultant value for the configuration attribute specified in the
      name argument.
     | 
   
  
    | 
      --1
     | 
    
Indicates an error;
errno
 is set to one of the following values:
- EINVAL -- The
name argument specifies an unknown or inapplicable 
characteristic.
 - EBADF -- the
filedes argument is not a valid file descriptor.
  
     | 
   
 
 
 
fprintf
 
Performs formatted output to a specified file.
 
 
Format
#include <stdio.h>
int fprintf (FILE *file_ptr, const char *format_spec, 
...);
 
  
 
Arguments
file_ptr
A pointer to the file to which the output is directed.
format_spec
A pointer to a character string that contains the format specification. 
For more information on format specifications and conversion 
characters, see Chapter 2.
...
Optional expressions whose resultant types correspond to conversion 
specifications given in the format specification.
If no conversion specifications are given, the output sources can be 
omitted. Otherwise, the function calls must have exactly as many output 
sources as there are conversion specifications, and the conversion 
specifications must match the types of the output sources.
 
Conversion specifications are matched to output sources in 
left-to-right order. Any excess output sources are ignored.
  
 
Description
An example of a conversion specification follows:
 
  
    
       
      
#include <stdio.h> 
 
main() 
{ 
   int  temp = 4, temp2 = 17; 
 
   fprintf(stdout, "The answers are %d, and %d.", temp, temp2); 
} 
 |   
Sample output (to the stdout file) from the previous example is as 
follows:
 
 
  
    
       
      
The answers are 4, and 17. 
 
 |   
For a complete description of the format specification and the output 
source, see Chapter 2.
  
 
Return Values
  
    | 
      x
     | 
    
      The number of bytes written, excluding the null terminator.
     | 
   
  
    | 
      Negative value
     | 
    
Indicates an error. The function sets
errno
 to one of the following:
- EILSEQ -- Invalid character detected.
 - EINVAL -- Insufficient arguments.
 - ENOMEM -- Not enough memory available for conversion.
 - ERANGE -- Floating-point calculations overflow.
 - EVMSERR -- Non-translatable VMS error.
vaxc$errno
 contains the VMS error code. This might indicate that conversion to a 
 numeric value failed because of overflow.
  
     | 
   
  
    | 
       
     | 
    
The function can also set
errno
 to the following as a result of errors returned from the I/O subsystem:
- EBADF -- The file descriptor is not valid.
 - EIO -- I/O error.
 - ENOSPC -- No free space on the device containing the file.
 - ENXIO -- Device does not exist.
 - EPIPE -- Broken pipe.
 - ESPIPE -- Illegal seek in a file opened for append.
 - EVMSERR -- Non-translatable VMS error.
vaxc$errno
 contains the VMS error code. This indicates that an I/O error occurred 
 for which there is no equivalent C error code.
  
     | 
   
 
 
  
         | 
	 
	  | 
	 
		 
		 |