Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

fputc - Write a character to a file

&pagelevel(4)&pagelevel

Definition

#include <stdio.h>

int fputc(int c, FILE *fp);

fputc writes the character c to a file (with file pointer fp) at the current read/write position.

Return val.

Written character c as a positive integer value

if successful.

EOF

otherwise.

Notes

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 reads characters from SYSDTA and outputs them to SYSOUT.

#include <stdio.h>
#include <stdlib.h>
void copy(void);
FILE *fp_in, *fp_out;
int main(void)
{
   fp_in = fopen("(SYSDTA)","r");
   fp_out = fopen ("(SYSOUT)","w");
   copy();
   fclose(fp_in);
   fclose(fp_out);
   return 0;
}
void copy(void)
{
  int c;
  while((c = fgetc(fp_in)) != EOF)
    fputc((char)c,fp_out);
}

See also

fopen, fopen64, fputwc, putc, putchar