Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

putc - Write a character to a file

&pagelevel(4)&pagelevel

Definition

#include <stdio.h>

int putc(int c, FILE *fp);

putc writes the character c to the file with file pointer fp at the current read/write position.

Return val.

The written character c


if successful.

EOF

otherwise.

Notes

putc is implemented both as a macro and as a function (see section “Functions and macros”).

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 the standard input and writes them to the file
fnam.

#include <stdio.h>
FILE *fp;
int c;
int main(void)
{
  fp = fopen("fnam","w");
  while((c=getchar()) != EOF)
        putc((char)c,fp);
  fclose(fp);
  return 0;
}

See also

fputc, printf, putchar, fopen, fopen64, putwc