putc
int  putc (int character, FILE * stream);
stdio.h
cplusplus.com  

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. Although it is declared as int, the function converts it to unsigned char 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.
  Note that when you work with binary files EOF is a valid character and you must use ferror() function to check if it has been an error.

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

Example.

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

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