getw(3C)
_________________________________________________________________
getw function
Read an integer value from the input buffer.
_________________________________________________________________
Calling Sequence
#include <stdio.h>
FILE *fp;
int num, getw();
num = getw(fp);
where fp is a pointer to a FILE stream.
num is an integer variable.
Description
Use the getw function to read the next word (an integer value)
from the input buffer; this function assumes that the file is
open. The include file stdio.h defines getw.
Returns
The getw function returns the integer value of the next word.
The function returns EOF (-1) on end of file, but since -1 is a
legal integer, use the feof macro to test for end of file.
Related Functions
See also the getc, gets, and putw functions and the feof macro.
Example
/* Program test for the getw() function */
#include <stdio.h>
#include <dglib.h>
FILE *fp, *fopen();
int num, getw(), sum = 0, c = 0;
main(argc, argv)
int argc;
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
getw(3C)
char *argv[];
{
fp = fopen(argv[1], "r");
for(;;) {
num = getw(fp);
if(feof(fp))
break;
sum += num;
c++;
}
printf("%d = sum of integers in %s.\n", sum, argv[1]);
printf("Number of integers: %d\n", c);
}
A call to the program test with the valid filename input_nos,
which contains binary representations of the first six digits,
generates the output
21 = sum of integers in input_nos.
Number of integers: 6
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)