Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

putw - Write a word at a time into a file

&pagelevel(4)&pagelevel

Definition

#include <stdio.h>

int putw(int w, FILE *fp)

putw writes a machine word into the file with file pointer fp at the current read/write position.

Return val.

The written w

EOF

if successful.

otherwise.

Notes

Since word length and the order of bytes 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 putw does not explicitly indicate errors (-1 is a valid integer value), you should also
use ferror to check whether an error occurred before or after the write operation.

The characters are not written immediately to the external file but are stored in an internal
C buffer (see section “Buffering” (Basic terms)).

Control characters for white space (\n, \t, etc.) are converted to their appropriate effect when
output to text files, depending on the type of text file (see section “White space” (Basic terms)).

Example

The following program transfers the contents of the file input to the file output, one word at
a time.

#include <stdio.h>
FILE *fp_in, *fp_out;  int w;
int main(void)
{
  fp_in = fopen("input","r");
  fp_out = fopen("output","w");
  while(!feof(fp_in) && !ferror(fp_in) && !ferror(fp_out))
       {
         w = getw(fp_in);
         putw(w,fp_out);
       }
  fclose(fp_in);  fclose(fp_out);
  return 0;
}

See also

getw