Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

getw - Read wordwise from a file

&pagelevel(4)&pagelevel

Definition

#include <stdio.h>

int getw(FILE *fp);

getw reads a machine word from the file with the file pointer fp and positions the read/write
pointer after the word read.

A machine word may be conceived of as a binary integer value.

Return val.

word read as an integer value

if successful.

EOF

or end of file or error.

Notes

Since word length and byte arrangement are system-dependent, it is possible that files
written with putw on a non-BS2000 operating system may not be readable with getw in
BS2000.

Since EOF represents a valid integer value, you should use the functions feof and
ferror to check for end of file or error conditions.

The following applies in the case of text files with SAM access mode and variable record
length for which a maximum record length is also specified: When the specification
split=no was entered for fopen, records of maximum record length are not concatenated
with the subsequent record when they are read. By default or with the specification
split=yes, when a record with maximum record length is read, it is assumed that the
following record is the continuation of this record and the records are concatenated.

Example

The following program fragment reads wordwise from the file with file pointer fp until end of
file is reached.

int buf[MAX];
int i = 0;
FILE *fp;
while(!feof(fp) && !ferror(fp))
     buf[i++] = getw(fp);

See also

putw