cplusplus.com > reference > cstdio > putc
putc
<stdio.h>
cplusplus.com  
int  putc (int character, FILE * stream);

Write character to stream.
  Writes character to the current position in the specified stream and increase the file pointer to point to next character.
  This routine is normally implemented as a macro with the same result as fputc.

Parameters.

character
Character to be written. The function casts the int parameter to its unsigned char equivalent before writing it.
stream
pointer to an open file.

Return Value.
  If there are no errors the written character is returned. If an error occurs, EOF is returned.

Portability.
  Defined in ANSI-C. Compatible with K&R.

Example.

/* putc example: alphabet writer */
#include <stdio.h>

int main ()
{
  FILE * pFile;
  char c;

  pFile=fopen("alphabet.txt","wt")
  for (c = 'A' ; c <= 'Z' ; c++) {
    putc (n , pFile);
    }
  fclose (pFile);
  return 0;
}
  This program creates a file called alphabet.txt and writes ABCDEFGHIJKLMNOPQRSTUVWXYZ on it.

See also.
  fgetc, fputc, fwrite, getchar, putchar


© The C++ Resources Network, 2000