getw() — Get a machine word from a stream

Standards

Standards / Extensions C or C++ Dependencies

XPG4
XPG4.2

both  

Format

#define _XOPEN_SOURCE
#include <stdio.h>

int getw(FILE *stream);

General description

The getw() function reads the next word from the stream. The size of the word is the size of an int, and varies from machine to machine. The getw() function presumes no special alignment in the file.

The getw() function may mark the st_atime field of the file associated with stream for update. The st_atime field will be marked for update by the first successful execution of fgetc(), fgets(), fread(), getc(), getchar(), gets(), fscanf() or scanf() using stream that returns data not supplied by a prior call to ungetc().

Note:

This function is kept for historical reasons. It was part of the Legacy Feature in Single UNIX Specification, Version 2, but has been withdrawn and is not supported as part of Single UNIX Specification, Version 3. New applications should use character-based input functions to replace getw() for portability.

If it is necessary to continue using this function in an application written for Single UNIX Specification, Version 3, define the feature test macro _UNIX03_WITHDRAWN before including any standard system headers. The macro exposes all interfaces and symbols removed in Single UNIX Specification, Version 3.

Returned value

If successful, getw() returns the next word from the input stream pointed to by stream. If the stream is at End Of File (EOF), the End Of File indicator for the stream is set and getw() returns EOF. If a read error occurs, the error indicator for the stream is set, getw() returns EOF and sets errno to indicate the error.

Refer to fgetc() — Read a character for errno values.

Because the representation of EOF is a valid integer, applications wishing to check for errors should use ferror() and feof().

Related information